2014-03-28 36 views
0

嘿,我是iPhone的新手,我一直在嘗試使用ARC來製作一種類似的應用程序。我使用UIImagePickerController從相機捕捉圖像。有時,當我點擊相機按鈕..然後它工作正常,但有時它顯示如下截圖預覽屏幕,然後用戶必須點擊UIImagePicker預覽取消按鈕,然後再次點擊相機按鈕捕捉圖像成功..可以有人告訴我爲什麼我得到這個問題的原因?iPhone中的UIImagePickerController問題?

enter image description here

這裏是我的代碼:

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
imagePickerController.delegate = self; 
imagePickerController.allowsEditing = YES; 
imagePickerController.sourceType = sourceType; 
[self presentViewController:imagePickerController animated:YES completion:nil]; 

謝謝您的幫助。

+0

您沒有設置源類型。 –

回答

1

你的代碼看起來很好,但我知道UIImagePicker是資源消耗。

我認爲它只是優化一次實例化。當你想目前它使用

self.imagePickerController = [[UIImagePickerController alloc] init]; 
self.imagePickerController.delegate = self; 
self.imagePickerController.allowsEditing = YES; 
self.imagePickerController.sourceType = sourceType; 

然後:把這個在你的viewWillAppear中方法

[self presentViewController:self.imagePickerController animated:YES completion:nil]; 

我注意到,這是更快的方式來呈現這種方式。讓我知道它是否解決了你的問題。

+0

@foOgThanks您的快速回復..我將適用您的解決方案..我可以給我所有的代碼在dispatch_get_main_queue中呈現UIImagePickerController,那麼它將工作與否? – user2786

+0

謝謝@foOg它正在爲我工​​作.. – user2786

+0

我不認爲你需要在main_queue上調用它,我從來沒有這樣做。它接縫的框架已經確保它將在主線程 – foOg

0

對於相機用戶這些

_imgPickerController = [[UIImagePickerController alloc]init]; 
[_imgPickerController setDelegate:self]; 
[_imgPickerController setSourceType:UIImagePickerControllerSourceTypeCamera]; 
_imgPickerController.showsCameraControls = YES; 
[self presentViewController:_imgPickerController animated:NO completion:Nil]; 

不要忘了導入這兩個代表

UIImagePickerControllerDelegate and UINavigationControllerDelegate 
相關問題