将相机锁定在横向



我有一个应用程序,可以让用户用相机拍照。 我只想允许用户拍摄风景照片,而不是纵向照片。 有没有办法锁定相机方向?

以下是我正在使用的代码:

func takePhoto() {
    //If a camera is available on this device, go to camera.  If not, present an error message.
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
        //Create the image picker controller
        imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = .Camera
        //Present the camera view
        presentViewController(imagePicker, animated: true, completion: nil)
    }
    else {
        let alert = UIAlertController(title: "Error", message: "There is no camera available", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: {(alertAction) in alert.dismissViewControllerAnimated(true, completion: nil)}))
        self.presentViewController(alert, animated: true, completion: nil)
    }
}

有没有办法让我锁定相机方向

相机是一个物理对象。它的方向与你的应用无关。"锁定相机方向"的唯一方法是伸出手抓住用户的手腕,这样他/她就无法转动设备。

最新更新