如何在iOS中将摄像机视图方向锁定到横向?

时间:2017-03-04 11:27:42

标签: ios swift camera orientation

我想在横向模式下修复我的相机视图。并且当用户将视图旋转为纵向时也会显示警报。有什么解决方案吗?

1 个答案:

答案 0 :(得分:0)

将它放在视图控制器中:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.current.orientation.isLandscape {
        print("will turn to landscape")
    } else {
        print("will turn to portrait")
        //print an alert box here
        UIDevice.current.setValue(UIInterfaceOrientation.landscapeLe‌​ft.rawValue, forKey: "orientation")
    }
}

来源:How to detect orientation change?

或者将其放在需要处于风景中的视图中:

override func shouldAutorotate() -> Bool {
    return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscape
}

但是这个人不能发布警报。