iPhoneで基本的な写真撮影をしようとしています。次のコードを使用してカメラを表示しました。
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
return YES;
}
これは正常に機能しますが、処理関数を定義すると、次のようになります。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
}
[使用]ボタンを押すと、imagePickerコントロールがフリーズします。クラッシュせず、例外もスローせず、コードは何かを実行していますが、画面にはフリーズしたimagePickerコントロールが表示されます。ハンドラーが空の場合でも、コントロールはフリーズします。ハンドラーを削除すると、カメラは正常に消え、カメラがアクティブ化された場所からのビューが表示されます...ここで重要な何かを見逃しましたか?
更新: 画像をUIImageViewに割り当てようとしましたが、コードが実行され、関数が終了しました。それで、カメラは画面に残ります。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
UIImage* original =[info objectForKey:@"UIImagePickerControllerOriginalImage"];
[[self imgWLItemImage] setImage:[UIImage imageWithCGImage:original.CGImage scale:0.25 orientation:original.imageOrientation]];
}