iOS growth path-call camera and album features (GO)

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/like7xiaoben/article/details/8465237

  1. Set the sourcetype as the camera, then determine if the camera is available (ipod), no camera, no sourcetype set as photo gallery
  2. Uiimagepickercontrollersourcetype sourcetype = Uiimagepickercontrollersourcetypecamera;
  3. if (![ Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {
  4. SourceType = uiimagepickercontrollersourcetypephotolibrary;
  5. //    }
  6. SourceType = Uiimagepickercontrollersourcetypecamera; Camera
  7. SourceType = uiimagepickercontrollersourcetypephotolibrary; Photo Gallery
  8. SourceType = Uiimagepickercontrollersourcetypesavedphotosalbum; Saved photos
  9. Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init]; //Initialize
  10. Picker.delegate = self;
  11. picker.allowsediting = YES; //settings can be edited
  12. Picker.sourcetype = sourcetype;
  13. [Self presentmodalviewcontroller:picker animated:yes]; //Enter the camera interface
  14. [Picker release];


Open Album: (differentiate between pad and iphone)

For iphone:

[CPP]View Plaincopy
  1. Uiimagepickercontroller *pickerimage = [[Uiimagepickercontroller alloc] init];
  2. if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary]) {
  3. Pickerimage.sourcetype = uiimagepickercontrollersourcetypephotolibrary;
  4. //pickerimage.sourcetype = uiimagepickercontrollersourcetypesavedphotosalbum;
  5. Pickerimage.mediatypes = [Uiimagepickercontroller availableMediaTypesForSourceType:pickerImage.sourceType];
  6. }
  7. Pickerimage.delegate = self;
  8. pickerimage.allowsediting = NO;
  9. [Self presentmodalviewcontroller:pickerimage animated:yes];
  10. [Pickerimage release];


For ipad:

[CPP]View Plaincopy
  1. Uiimagepickercontrollersourcetype sourcetype = uiimagepickercontrollersourcetypephotolibrary;
  2. //sourcetype = uiimagepickercontrollersourcetypesavedphotosalbum;//Saved photos
  3. Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];
  4. Picker.delegate = self;
  5. picker.allowsediting = NO; //whether to allow editing
  6. Picker.sourcetype = sourcetype;
  7. /* 
  8. If rendered from a navigation button, use:
  9. PresentPopoverFromBarButtonItem:permittedArrowDirections:animated:;
  10. If you want to render from a view, use:
  11. PresentPopoverFromRect:inView:permittedArrowDirections:animated:
  12. If the device is rotated, the position positioning error needs to be repositioned in the following method of the parent view controller:
  13. Didrotatefrominterfaceorientation: (re-set rect inside this method body)
  14. Then call again:
  15. -(void) Presentpopoverfromrect: (cgrect) rect inview: (UIView *) View permittedarrowdirections: ( Uipopoverarrowdirection) arrowdirections animated: (BOOL) animated
  16. */
  17. //uipopovercontroller can only be used on ipad devices, and is used to display temporary content that is always displayed at the front of the current view and disappears automatically when clicked elsewhere in the interface.
  18. Uipopovercontroller *popover = [[Uipopovercontroller alloc]initwithcontentviewcontroller:picker];
  19. Self.imagepicker = PopOver;
  20. //permittedarrowdirections Setting the arrow direction
  21. [Self.imagepicker presentpopoverfromrect:cgrectmake (0, 0, +) InView:self.view permittedarrowdirections: Uipopoverarrowdirectionany Animated:yes];
  22. [Picker release];
  23. [PopOver release];

Click on the picture in the photo album when the camera is finished, click Use to trigger the method

-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info

Click Cancel to invoke the method

-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker

Example: http://download.csdn.net/download/like7xiaoben/4958356

iOS growth path-call camera and album features (GO)

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.