Talking about the iPhone mobile phone photo taking function and the photo library selection function call

Source: Internet
Author: User

DiscussionIPhoneMobile phonePhotographFunctions and photosCredits LibrarySelecting function call is the content to be introduced in this article. There is not much content, mainly through code implementation. Let's look at the content.

First, you must implement UIImagePickerControllerDelegate and UINavigationControllerDelegate.

Next, define the button:

 
 
  1. // Upload one from the album
  2. UIButton * btn1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
  3. Btn1.frame = CGRectMake (60.0, 237.0, 200.0, 32.0 );
  4. [Btn1 setTitle: @ "selecting images from the media repository" forState: UIControlStateNormal];
  5. [Btn1 addTarget: self action: @ selector (picker) forControlEvents: UIControlEventTouchUpInside];
  6. UIButton * btn2 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
  7. Btn2.frame = CGRectMake (60.0, 290.0, 200.0, 32.0 );
  8. [Btn2 setTitle: @ "get image from camera" forState: UIControlStateNormal];
  9. [Btn2 addTarget: self action: @ selector (picker1) forControlEvents: UIControlEventTouchUpInside];

Button implementation method:

 
 
  1. // Select from the Photo Library
  2.  
  3. -(Void) picker
  4.  
  5. {
  6.  
  7. Imagepicker = [[UIImagePickerController alloc] init];
  8.  
  9. Imagepicker. delegate = self;
  10.  
  11. Imagepicker. sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  12. Imagepicker. modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  13. Imagepicker. allowsEditing = YES;
  14. [Self presentModalViewController: self. imagepicker animated: YES];
  15. }
  16. // Obtain from the camera
  17. -(Void) picker1
  18. {
  19. Imagepicker = [[UIImagePickerController alloc] init];
  20. Imagepicker. delegate = self;
  21. Imagepicker. sourceType = UIImagePickerControllerSourceTypeCamera;
  22. Imagepicker. modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  23. Imagepicker. allowsEditing = YES;
  24. [Self presentModalViewController: self. imagepicker animated: YES];
  25. }

Proxy method:

 
 
  1. // Initialize and select
  2. -(Void) imagePickerController :( UIImagePickerController *) picker
  3. DidFinishPickingImage :( UIImage *) image
  4. EditingInfo :( NSDictionary *) editingInfo
  5. {
  6. MyImageView. image = image;
  7. [[Picker parentViewController] dismissModalViewControllerAnimated: YES];
  8. }
  9. // Select
  10.  
  11. -(Void) imagePickerControllerDidCancel :( UIImagePickerController *) picker
  12. {
  13. [Picker dismissModalViewControllerAnimated: YES];
  14. }

Summary:IPhoneMobile phonePhotographFunctions andPhoto GalleryThis article is helpful to you.

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.