Autolayout旋转无法正常工作

时间:2014-07-11 23:36:03

标签: objective-c ios7 autolayout ios-autolayout

当我在IB中使用Autolayout ON旋转设备时,不会调用以下方法。

willRotateToInterfaceOrientation:duration:

首先,上述方法是否不需要自动布局?在关闭Autolayout的情况下调用该方法。我正在尝试更改旋转视图的背景图像,不确定如何使用autolayout constaints ON来实现这一点?

我也尝试使用Moin的过程,但是我有一个巨大的视图层次结构,从superview开始调用这些方法,并且我在其他方法中有很多其他代码。所以它没有帮助

didRotateFromInterfaceOrientation  

2 个答案:

答案 0 :(得分:1)

答案简短: 使用AutoLayout -willRotateToInterfaceOrientation:duration: 工作

答案很长: 假设您正在使用NIB,那么很多复合问题都可能出错;我编制了这份清单:

  1. 您是否按@JoshJustice在Loaded nib but the view outlet was not set - new to InterfaceBuilder
  2. 的建议在IB中设置了自定义UIViewController
  3. 您是否按照UIViewController does not auto rotate
  4. 的@nybon的建议正确处理自动轮播
  5. 您是否按照Handling autorotation for one view controller in iOS7
  6. 上@NateFlink的建议在plist设置了全局定位
  7. 您的自定义UIViewController是否使用不正确的值回复-supportedInterfaceOrientations?请参阅@AndrewHershberger在preferredInterfaceOrientationForPresentation must return a supported interface orientation (iOS 6)
  8. 推荐的回复

答案 1 :(得分:1)

-willRotateToInterfaceOrientation:duration:在根视图控制器及其所有子视图控制器上被调用,并使用autolayout。如果你想在特定的viewcontroller上调用这些方法,它必须是根视图控制器的子视图控制器。

我花了一段时间才弄清楚从根到最后一个viewcontroller的层次结构在某些时候出现了问题。我只需将其添加回子视图控制器。