【发布时间】:2016-05-11 13:01:01
【问题描述】:
如何使用代码将设备方向更改为纵向?
为了从视图控制器纵向打开相机和库。
我想在这个按钮中加入:
@IBAction func openCamera(sender: AnyObject) { ///accion del 波顿卡马拉
// Create image picker controller let image = UIImagePickerController() image.delegate = self image.sourceType = UIImagePickerControllerSourceType.Camera image.cameraDevice = UIImagePickerControllerCameraDevice.Front self.presentViewController(image, animated: true, completion: nil) }
我收到了这个错误:
由于未捕获的异常而终止应用程序 'UIApplicationInvalidInterfaceOrientation',原因:'支持 方向与应用程序没有共同的方向,并且 [PLUICameraViewController shouldAutorotate] 返回 YES' *** 第一次抛出调用堆栈:(0x18150ee38 0x180b73f80 0x18150ed80 0x1866d1af0 0x1866db150 0x1866db0c8 0x1866d9bb0 0x186653910 0x1866536ac 0x1866536ac 0x1866536ac 0x186652c40 0x181e40d50 0x186652ac4 0x186660578 0x18675a11c 0x186759a40 0x1869b8740 0x18690afd8 0x186918990 0x18664a4a4 0x1814c47b0 0x1814c2554 0x1814c2984 0x1813ecd10 0x182cd4088 0x1866c1f70 0x1000675ac 0x180f8a8b8) libc++abi.dylib: 以未捕获的异常终止 输入 NSException (lldb)
当我使用时
> presentViewController(cameraViewController, animated: true,
> completion: nil)
> }
> */
>
> // Create image picker controller
>
>
> let image = UIImagePickerController()
>
> image.delegate = self
>
> image.sourceType = UIImagePickerControllerSourceType.Camera
> image.cameraDevice = UIImagePickerControllerCameraDevice.Front
> self.presentViewController(image, animated: true, completion: nil)
> }
【问题讨论】:
-
强制设备方向不是要走的路。问题也不是设备,而是界面方向以及您在 AppDelegate 或应用程序的 plist 中指定的。你禁止人像吗?然后允许它:P
-
这确实意味着您的视图控制器必须支持它。但它将为需要它的 VC 启用它