首页 文章

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

提问于
浏览
0

我有 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

    解决了使用:

    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!
            }
    

相关问题