Open the camera:
// Set sourceType to the camera first, and then determine whether the camera is available (ipod) without a camera. You cannot set sourceType to the Photo Library UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; // if (! [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {// sourceType = Hangzhou; // sourceType = Shanghai; // camera // sourceType = Shanghai; // Image Library // sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; // Save the photo UIImagePickerController * picker = [[UIImagePickerController alloc] init]; // initialize picker. delegate = self; picker. allowsEditing = YES; // You can edit picker. sourceType = sourceType; [self presentModalViewController: picker animated: YES]; // enter the camera interface [picker release];
Open album: (differentiate pad and iphone)
For iphone:
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:
UIImagePickerControllerSourceType sourceType = Hangzhou; // Save the photo UIImagePickerController * picker = [[UIImagePickerController alloc] init]; picker. delegate = self; picker. allowsEditing = NO; // whether to allow editing picker. sourceType = sourceType;/* If displayed from a navigation button, use: presentpoverfrombarbuttonitem: permittedArrowDi Rections: animated:; if you want to render a view, use: presentpoverfromrect: inView: permittedArrowDirections ctions: animated: if the device is rotated, location error needs to be located again in the following method of the parent View Controller: didRotateFromInterfaceOrientation :( reset rect in this method body) and then call:-(void) presentpoverfromrect :( CGRect) rect inView :( UIView *) view permittedArrowDirections :( UIPopoverArrowDirection) arrowDirections animated :( BOOL) animated * // UIPopoverController can only be used on ipad devices. Temporary content is always displayed at the front of the current view. It disappears automatically when you click somewhere else on the page. UIPopoverController * popover = [[UIPopoverController alloc] initWithContentViewController: picker]; self. imagePicker = popover; // permittedArrowDirections sets the arrow Direction [self. imagePicker presentpoverfromrect: CGRectMake (0, 0,300,300) inView: self. view permittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES]; [picker release]; [popopover release];
How to trigger when you click use after the photo camera in the photo album is taken
-(Void) imagepickercontroller :( uiimagepickercontroller *) picker didfinishpickingmediawithinfo :( nsdictionary
*) Info
Click the method called by cancel.
-(Void) imagepickercontrollerdidcancel :( uiimagepickercontroller *) picker
Example: http://download.csdn.net/download/like7xiaoben/4958356