在横向模式下调用UIViewcontroller时出现UIScrollview错误

时间:2016-01-06 18:07:39

标签: ios uiviewcontroller uiscrollview storyboard

我有UIScrollview加载了其他两个UIViewControllers。主UIViewcontroller的方向已锁定为纵向模式,而最后一个视图的按钮可调用另一个uiviewcontroller,其中UIImageview需要根据移动方向进行旋转。

一切正常,但如果我以横向模式旋转移动设备,然后按下按钮调用UIViewcontroller中的图像,UIScrollview显示在中途,或者从第1页返回从图像返回到主滚动视图。

UIViewcontroller使用以下方式锁定:

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

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

这里是项目文件:https://github.com/salvonos/OrientationScrollView

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

解决使用:

    var autoRotate: Bool?
    var orientationMode: UIInterfaceOrientationMask?

    override func viewDidLoad() {
            super.viewDidLoad()

            autoRotate = false
            orientationMode = UIInterfaceOrientationMask.Portrait
    }


    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        self.autoRotate = true
        self.orientationMode = UIInterfaceOrientationMask.All
    }


     override func shouldAutorotate() -> Bool {
            return autoRotate!
        }


        override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
            return orientationMode!
        }