UIImagePickerController拍照後黑屏

weixin_33806914發表於2017-02-27

最近開發的一個專案中,UIImagePickerController拍照後黑屏,點選確認後也可以顯示照片,而且每次黑屏出現的時候會有CGAffineTransformInvert: singular matrix錯誤資訊。最初一直再上述錯誤中徘徊,找解決方案。查詢多次,stackoverflow上各種可能的方法都試了,依然無果。百思不得其解!到底哪裡出現了問題呢?

無奈,靜下來,想,首先我要找到問題必然出現的原因,於是,經過反覆測試,終於到到出現的點。專案中引入了一個三房庫彈框JCAlterView,每次觸發彈框後,在去拍照的地方必然出現預覽黑屏的問題。試著把彈框改成自定義的之後,問題解決了!!本來開始想去修改JCAlterView底層。發現底層操作UIApplication的rootViewController了。無奈,最後直接自定義樣式換了JCAlterView,問題解決了。

唯一遺憾的是,由於時間問題,我沒有追究為何改變UIApplication的rootVIewController後再次拍照會出現黑屏錯誤。

附上stackoverflow的各種解決方法。

【連結】yourcommunities

http://stackoverflow.com/questions/25884801/ios-8-snapshotting-a-view-that-has-not-been-rendered-results-in-an-empty-snapsho

http://stackoverflow.com/questions/21538781/uiimagepickercontroller-camera-blank-snapshot-image

down vote

I found the solution to my problem thanks to DevC's comment pointing me in the right direction. I used an ActionSheet to present the UIImagePickerController, so when clicking a button on it the animation still runs while the picker is opened. I solved it by closing the picker before I run the code that triggers thepicker:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

[actionSheet dismissWithClickedButtonIndex:999 animated:NO]; //non-existing button index so it doesn't trigger anything again

// Rest of code here (UIImagePickerController trigger)

}

相關文章