目前我在UIImagePickerController
上使用自定義覆蓋圖,調用takePicture()
來捕獲圖像。但是,調用代理方法didFinishPickingMediaWithInfo
需要幾秒鐘的時間。我聽說過使用AVCaptureSession
來控制相機。這會讓我獲得更快的拍攝速度(類似於Snapchat)嗎?還是有,我可以AVCaptureSession vs UIImagePickerController速度
感謝
編輯
我執行我的圖像採集如下任何其他方式。
首先我初始化一個UIImagePickerController,使用稱爲CustomCameraOverlayView
的UIView子類作爲疊加視圖,並將其呈現在模態視圖中。 CustomCameraOverlayView
的代表設置爲UIImagePickerControllerDelegate
(個人),因此我可以撥打CustomCameraOverlayView
中的takePicture
。
imagePickerController = UIImagePickerController()
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
imagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Rear
imagePickerController.editing = true
imagePickerController.delegate = self
imagePickerController.showsCameraControls = false
var customCameraOverlayView = CustomCameraOverlayView()
customCameraOverlayView.delegate = self
imagePickerController.cameraOverlayView = customCameraOverlayView
imagePickerController.cameraOverlayView!.frame = self.view.frame
var screenBounds: CGSize = UIScreen.mainScreen().bounds.size
var imageHeight = (screenBounds.width/3)*4
var scale = screenBounds.height/imageHeight
imagePickerController.cameraViewTransform = CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale), CGAffineTransformMakeTranslation(0, (screenBounds.height - imageHeight)/2))
self.presentViewController(imagePickerController, animated: true, completion: nil)
}
然後CustomCameraOverlayView
裏面我從IB到我的代碼「拍照」按鈕,設置了行動。它發回消息給代表拍攝照片:
@IBAction func takePicture(sender: UIButton) {
delegate!.imagePickerController.takePicture()
}
幾秒鐘後,調用委託方法。什麼可能會減慢我的執行速度?
嗯有趣,我已經更新了我的答案,包括編碼。 – Tometoyou