Ios simple gesture operation-modal View

Source: Internet
Author: User

1. Create a single view project

2. ViewController. h

@ Interface ViewController: UIViewController
 
  
{UIImageView * _ imgView; // display image} @ end
 

3. ViewController. m initialize _ imgView

// Initialize image view _ imgView = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0,320,460)]; _ imgView. backgroundColor = [UIColor yellowColor]; _ imgView. userInteractionEnabled = YES; // remember to enable the user interaction in the Image view [self. view addSubview: _ imgView]; [_ imgView release];


4. Add a gesture operation for _ imgView

// Gesture UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (selectImage)]; // tap. numberOfTapsRequired = 2; // double-click the trigger // tap. numberOfTouchesRequired = 2; // double-finger touch trigger [_ imgView addGestureRecognizer: tap]; [tap release];

5. Implement the selectImage Method

-(Void) selectImage {UIImagePickerController * ipc = [[UIImagePickerController alloc] init]; ipc. sourceType = UIImagePickerControllerSourceTypePhotoLibrary; // you can specify the image ipc. delegate = self; [self presentViewController: ipc animated: YES completion: nil]; // modal view [ipc release];}

6. Implement two proxy Methods

// Select image call-(void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info {_ imgView. image = [info objectForKey: Custom]; // [self dismissViewControllerAnimated: YES completion: nil];} // click Cancel call-(void) imagePickerControllerDidCancel :( UIImagePickerController *) picker {[self dismissViewControllerAnimated: YES completion: nil];}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.