如何在iPad旋转时旋转单个视图

时间:2013-09-20 20:40:47

标签: ios ipad uiview rotation

我使用iOS 7在iPad上开发应用程序。此应用程序的主要UIView(viewA)始终是构建的横向。在主视图内部还有另一个小的UIView(viewB)。两者都由具有此方法的相同mainViewController控制

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
 }

从横向iPad开始,当我在纵向位置旋转iPad时,viewA和视图B保持原样。好的。

现在我想做出改变。确切地说,我想要的是,当iPad从横向旋转到纵向时,viewA仍然像以前一样,但viewB会自动旋转。我能怎么做?我是否要为viewB创建单独的ViewController?

谢谢。

1 个答案:

答案 0 :(得分:0)

您需要扩展/继承ViewController并覆盖shouldAutorotateToInterfaceOrientation方法以返回视图B的正确方向

示例ViewControllerB.h:

@interface ViewControllerB : ViewControllerA {
}

ViewControllerB.m:

@implementation ViewControllerB

  - (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation {
    return true;
  }
@end