我有一个按钮,当用户按下它时,他会导航到相机拍照。
当他拍摄照片时,他按完了并返回控制器。但是当发生这种情况时,导航栏会在屏幕上显示,低于电话所具有的电池/信号条。奇怪的是,这种情况发生在4 / 4s而不是3gs
答案 0 :(得分:1)
在不知道更多细节的情况下回答这个问题是相当困难的,但是这里有一些代码用于调出相机,拍照,然后成功关闭相机。可以使用一行代码调用该方法:[self takePhoto];
- (void) takePhoto {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
//Clear out the UI first
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; -> use this if you want them to select from the library
[self presentViewController:picker animated:YES completion:nil];
} else {
//Device does not support a camera, show a message if desired
}
}
然后你需要一个委托代码,以便程序知道在拍摄或选择图像时该做什么以及如何关闭,这就是这段代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.workingImage = nil;
//I grab the image and store globally, but first I manually scale and rotate it if necessary
self.workingImage = [self scaleAndRotateImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
//I display the image in my UI view, so this chunk of code will size it properly
CGRect bound;
bound.origin = CGPointZero;
bound.size = img.size;
imageView.bounds = bound;
//Set the UI image view and dismiss the controller
[imageView setImage:self.workingImage];
[picker dismissModalViewControllerAnimated:YES];
}
显然,请确保您的控制器.h正确实现委托:
@interface ViewController : UIViewController<UIImagePickerControllerDelegate> { ... }
希望这有帮助吗?