如何将摄像头视图方向锁定为iOS横向?

问题描述:

我想修复我的相机视图在横向模式。并且当用户将视图旋转到肖像时也显示警告。有没有解决方案?如何将摄像头视图方向锁定为iOS横向?

在您的视图控制器将这个:

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 
} 

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

+0

@LijithVipin - portait被锁定意味着 –

+0

@ LiJithVipin我不明白你想说什么,你能详细说明一下吗? – paper1111