使用默认摄像头

时间:2015-07-10 02:53:53

标签: ios iphone swift

我正在制作一个带有3个标签栏和中间相机功能的应用程序。 我试图让用户在标签栏中标记相机并拍摄视频/照片。我成功编码,因此当按下标签栏中的相机按钮时相机会打开。当相机打开时,它与苹果公司的默认相机非常不同。没有像从照片到视频更改相机模式的选项。我写的代码如下。请帮忙!谢谢。

 import UIKit

typealias PhotoTakingHelperCallback = UIImage? -> Void

class PhotoTakingHelper : NSObject {

/** View controller on which AlertViewController and UIImagePickerController are presented */
weak var viewController: UIViewController!
var callback: PhotoTakingHelperCallback
var imagePickerController: UIImagePickerController?

init(viewController: UIViewController, callback: PhotoTakingHelperCallback) {
    self.viewController = viewController
    self.callback = callback

    super.init()

    showPhotoSourceSelection()
}
func showImagePickerController(sourceType: UIImagePickerControllerSourceType) {
    imagePickerController = UIImagePickerController()
    imagePickerController!.sourceType = sourceType
    imagePickerController!.showsCameraControls == true
    imagePickerController!.navigationBarHidden == false
    imagePickerController!.toolbarHidden == false
    imagePickerController!.allowsEditing == true
    imagePickerController!.startVideoCapture() == true

    self.viewController.presentViewController(imagePickerController!, animated: true, completion: nil)


}

func showPhotoSourceSelection() {
    // Only show camera option if rear camera is available
    if (UIImagePickerController.isCameraDeviceAvailable(.Rear)) {
       self.showImagePickerController(.Camera)
    }


}

}

It looks like a picture below.

1 个答案:

答案 0 :(得分:2)

要使视频选项可用,您需要将mediaTypes设置如下:

imagePickerController!.mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(.Camera)!

注意:设置布尔值时,必须使用单个等号:

imagePickerController!.showsCameraControls = true
imagePickerController!.navigationBarHidden = false
imagePickerController!.toolbarHidden = false
imagePickerController!.allowsEditing = true