ユーザーが押すと、カメラに移動して写真を撮るボタンがあります。
写真を撮ったら、完了を押してコントローラーに戻ります。しかし、それが起こると、ナビゲーションバーが画面に表示され、電話のバッテリー/信号バーより下になります。奇妙なことに、これは 4/4s では発生するが 3gs では発生しない。
ユーザーが押すと、カメラに移動して写真を撮るボタンがあります。
写真を撮ったら、完了を押してコントローラーに戻ります。しかし、それが起こると、ナビゲーションバーが画面に表示され、電話のバッテリー/信号バーより下になります。奇妙なことに、これは 4/4s では発生するが 3gs では発生しない。
もう少し詳細を知らずに質問に答えるのはかなり難しいですが、カメラを立ち上げ、写真を撮り、カメラを正常に閉じるために使用するコードを次に示します。このメソッドは、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> { ... }
お役に立てれば?