【问题标题】:How can I lock camera view orientation to landscape in iOS?如何在 iOS 中将相机视图方向锁定为横向?
【发布时间】:2017-03-04 11:27:42
【问题描述】:

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

【问题讨论】:

    标签: ios swift camera orientation


    【解决方案1】:

    把它放在你的视图控制器中:

    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
    }
    

    但是这个不能发布警报。

    【讨论】:

    • @LijithVipin - 肖像被锁定意味着
    • @LijithVipin 我不明白你想说什么,你能详细说明一下吗?
    猜你喜欢
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 2019-11-05
    • 1970-01-01
    相关资源
    最近更新 更多