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];}