【问题标题】:shouldAutorotateToInterfaceOrientation is not being called没有调用 shouldAutorotateToInterfaceOrientation
【发布时间】:2012-12-14 09:44:54
【问题描述】:

您好,我现在对视图控制器的方向有疑问。以下是我的 .h 文件。

@interface IPad_HomeViewController : UIViewController <UINavigationControllerDelegate>{
    UIAlertView *alertWithYesNoButtons;
}
@property (weak, nonatomic) IBOutlet UILabel *lblStatus;

@end

我在 .m 文件中实现了以下方法。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return NO;
}

然后我做了一个断点。我意识到 shouldAutorotateToInterfaceOrientation 完全没有被调用。不知道为什么它没有被调用。

请给我建议。 谢谢

【问题讨论】:

  • 您用来显示该视图的方法是指 addSubview 或 PresentModalViewController。

标签: objective-c xcode4 ios5


【解决方案1】:

我认为这是因为您的 UINavigationController 处理了调用。实现以下将其发送回 viewController。

- (BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

// pre-iOS 6 support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

【讨论】:

  • 感谢 Roland,我在supportedInterfaceOrientations 中看到了错误。在“iPad_HomeViewController*”类型的对象上找不到“属性“viewControllers”
  • 那么 'IPad_HomeViewController' 不是 UINavigationController 或它的子类。
【解决方案2】:

iOS 5 和 iOS 6 之间的旋转支持发生了很大变化。

转到项目的目标摘要页面并检查“iPhone/Ipod 部署信息”和“支持的接口方向”。您是否启用了设备旋转?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多