我有一个带有多个视图的导航控制器。大多数视图都是纵向视图,因此我将以下代码放在导航视图控制器中,将其锁定到纵向视图中
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> Int {
return UIInterfaceOrientation.Portrait.toRaw()
}这个效果很好,并且将我所有的视图锁定在纵向。然而,这是一个只需要在Landscape中的视图。如果我使用上面的代码,它会将我的Landscape View锁定为纵向模式,从而切断大部分视图。
有没有人能帮我在景观视图控制器中使用什么来锁定这个仅在景观中的特定视图。
我在用这个,但它不起作用。
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Landscape.toRaw())
}
override func shouldAutorotate() -> Bool{
// This method is the same for all the three custom ViewController
return true
}发布于 2015-04-11 01:47:50
对于小型应用程序,我通常使用的解决方案是让导航控制器询问视图本身的旋转首选项:
override func supportedInterfaceOrientations() -> Int {
return visibleViewController.supportedInterfaceOrientations()
}
override func shouldAutorotate() -> Bool {
return visibleViewController.shouldAutorotate()
}然后,在每个视图控制器中,您可以覆盖shouldAutorotate和supportedInterfaceOrientations,以便为每个控制器提供所需的行为。
另一个技巧是,为了确保您的视图可以旋转回所需的旋转,您可以使用此技巧有条件地允许旋转回纵向:
override func shouldAutorotate() -> Bool {
return !UIInterfaceOrientationIsPortrait(self.interfaceOrientation)
}https://stackoverflow.com/questions/25837617
复制相似问题