Reprinted from: http://blog.csdn.net/like7xiaoben/article/details/8465237
- Set the sourcetype as the camera, then determine if the camera is available (ipod), no camera, no sourcetype set as photo gallery
- Uiimagepickercontrollersourcetype sourcetype = Uiimagepickercontrollersourcetypecamera;
- if (![ Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {
- SourceType = uiimagepickercontrollersourcetypephotolibrary;
- // }
- SourceType = Uiimagepickercontrollersourcetypecamera; Camera
- SourceType = uiimagepickercontrollersourcetypephotolibrary; Photo Gallery
- SourceType = Uiimagepickercontrollersourcetypesavedphotosalbum; Saved photos
- Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init]; //Initialize
- Picker.delegate = self;
- picker.allowsediting = YES; //settings can be edited
- Picker.sourcetype = sourcetype;
- [Self presentmodalviewcontroller:picker animated:yes]; //Enter the camera interface
- [Picker release];
Open Album: (differentiate between pad and iphone)
For iphone:
[CPP]View Plaincopy
- Uiimagepickercontroller *pickerimage = [[Uiimagepickercontroller alloc] init];
- if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary]) {
- Pickerimage.sourcetype = uiimagepickercontrollersourcetypephotolibrary;
- //pickerimage.sourcetype = uiimagepickercontrollersourcetypesavedphotosalbum;
- Pickerimage.mediatypes = [Uiimagepickercontroller availableMediaTypesForSourceType:pickerImage.sourceType];
- }
- Pickerimage.delegate = self;
- pickerimage.allowsediting = NO;
- [Self presentmodalviewcontroller:pickerimage animated:yes];
- [Pickerimage release];
For ipad:
[CPP]View Plaincopy
- Uiimagepickercontrollersourcetype sourcetype = uiimagepickercontrollersourcetypephotolibrary;
- //sourcetype = uiimagepickercontrollersourcetypesavedphotosalbum;//Saved photos
- Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];
- Picker.delegate = self;
- picker.allowsediting = NO; //whether to allow editing
- Picker.sourcetype = sourcetype;
- /*
- If rendered from a navigation button, use:
- PresentPopoverFromBarButtonItem:permittedArrowDirections:animated:;
- If you want to render from a view, use:
- PresentPopoverFromRect:inView:permittedArrowDirections:animated:
- If the device is rotated, the position positioning error needs to be repositioned in the following method of the parent view controller:
- Didrotatefrominterfaceorientation: (re-set rect inside this method body)
- Then call again:
- -(void) Presentpopoverfromrect: (cgrect) rect inview: (UIView *) View permittedarrowdirections: ( Uipopoverarrowdirection) arrowdirections animated: (BOOL) animated
- */
- //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.
- Uipopovercontroller *popover = [[Uipopovercontroller alloc]initwithcontentviewcontroller:picker];
- Self.imagepicker = PopOver;
- //permittedarrowdirections Setting the arrow direction
- [Self.imagepicker presentpopoverfromrect:cgrectmake (0, 0, +) InView:self.view permittedarrowdirections: Uipopoverarrowdirectionany Animated:yes];
- [Picker release];
- [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)