2011-06-16 391 views
1

后,我有这样的代码来拍照在我的iPhone应用程序:iPhone拍照导致白屏拍照

-(IBAction) getPhoto:(id) sender { 
    UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 
    else{ 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    } 

    [self presentModalViewController:picker animated:YES]; 
} 

然后,我有这个其他控制器来管理拍摄的照片:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { 
    [picker.parentViewController dismissModalViewControllerAnimated:YES]; 
    imageTaken.image = image; 
    NSLog(@"saved!"); 
} 

我试图在我的iPhone 4(iOS 4.something)上启动应用程序,在拍摄照片并点击“使用”后,我得到一个白色屏幕。当直接在XCode(这次是iOS 5)启动的另一部手机上直接测试应用程序以检查日志时,我点击“使用”,但没有任何反应,并且日志被正确打印。

你知道发生了什么事吗?我认为,图片的屏幕并没有关闭,但我打电话dismissModalViewController ....

感谢,

Masiar

回答

1

你应该开除以这种方式模态视图控制器,

[self dismissModalViewControllerAnimated:YES]; 

而最好使用imagePickerController:didFinishPickingMediaWithInfo:,因为其他方法已被弃用。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    [self dismissModalViewControllerAnimated:YES]; 
    imageTaken.image = (UIImage *)[info objectForKey: UIImagePickerControllerEditedImage]; 
} 
+0

“[self dismissModalViewControllerAnimated:YES]''是如何工作的?我的应用程序有点杂乱,我的主视图中有这样的代码,即使这样也删除了图片的视图并让我继续使用我的应用程序? – Masiar 2011-06-16 13:13:00

+0

它完全按照['here']提到的方式工作(http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926- CH3-SW30)。它将关闭'self'提供的模式视图控制器。如果在模式视图控制器中调用,则消息被传回给呈现它的视图控制器。 – 2011-06-16 13:18:57

+0

我偶尔也会看到一个白色的屏幕,但我正在使用最新的函数来处理ImagePicker。我怀疑他在这里做的任何事情都是原因。 – Oscar 2012-02-07 23:28:15