【问题标题】:How to rotate a single view when iPad rotateiPad旋转时如何旋转单个视图
【发布时间】:2013-09-26 08:34:54
【问题描述】:

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

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

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

现在我想做出改变。确切地说,我希望当 iPad 从横向旋转到纵向时,viewA 保持原样,但 viewB 自动旋转。我能怎么做?我需要为 viewB 制作一个单独的 ViewController 吗?

谢谢。

【问题讨论】:

  • 尝试接收UIDeviceOrientationDidChangeNotification,并处理那里的情况。

标签: ios ipad uiview rotation


【解决方案1】:

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

ViewControllerB.h 示例:

@interface ViewControllerB : ViewControllerA {
}

ViewControllerB.m:

@implementation ViewControllerB

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

【讨论】:

  • “扩展视图控制器”是什么意思?
  • 我在回答中添加了一些示例代码。希望对您有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-16
  • 1970-01-01
相关资源
最近更新 更多