Need help hendling (dismissing) ImagePicker (camera) in objective-c (iphone)
i have a little problem with dismissing my camera view. im using the UIImagePickerController with this code-
-(void)viewDidAppear:(BOOL)animated{
UIImagePickerController *picker=[[UIImagePickerController alloc]init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=NO;
[picker.cameraOverlayView addSubview:mirrorOverlay];
picker.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:picker animated:YES];
[picker release];}
im using a custom button to close the camera and change the view back to my main view using this code-
-(IBAction)flipBack:(id)sender{
[self dismissModalViewControllerAnimated:YES];
my problem is when im pressing the button the View flipout and then going back in and call the camera again. i can't find a way to dismiss the camera and the view.
Please help. Thanks, Amir.
Update: Thanks for the help ! i figure it out ! my problem was that i was working with nib files of the camera, and when you want to use the camera in different way that was described on the delegate you should use View and not nib.
so my code was correct but in the wrong 开发者_如何学运维place and format. Thanks all !
if someone need help with it, I'm here to help back !
you need to dismiss the picker, by the looks of it you're dismissing the controller that presents the picker.
-(IBAction)flipBack:(id)sender{
[picker dismissModalViewControllerAnimated:YES];
}
You need to keep a reference to the picker
in this case (e.g: add UIImagePicker *picker; as a member to your viewcontroller class).
It seems you put code at wrong place because every time your viewDidAppear the picker will be presented instead of this you need to put image picker code on some button click.Then you can implement picker's delegate method like imagePickerDidCancel and imagePickerDidFinishPickingMedia to dismiss the picker implement imagePickerDidCancel or if you want you custom cancel method your code looks fine.
In iOS7 present/dismiss ModalViewController is deprecated for Camera Roll image picker.
To open image picker use:
[controller presentViewController:mediaUI animated:YES completion:nil]; // open image picker
To close or cancel image picker use:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil]; // close image picker
}
For more information best to look at: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/Articles/PickinganItemfromthePhotoLibrary.html
精彩评论