iOS 6 shouldAutorotate: 没有被调用 [英] iOS 6 shouldAutorotate: is NOT being called

查看:19
本文介绍了iOS 6 shouldAutorotate: 没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在互联网上寻找解决方案,但一无所获.我正在尝试使我的 iOS 5 应用程序与 iOS 6 兼容.我无法让方向的东西正常工作.我无法检测到何时将发生轮换.这是我正在尝试的代码:

I have been scouring the internet for a solution to this but am finding nothing. I am trying to make my iOS 5 app iOS 6 compatible. I cannot get the orientation stuff to work right. I am unable to detect when a rotation is about to happen. Here is the code I am trying:

- (BOOL)shouldAutorotate {
    return NO;
}

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

新的supportedInterfaceOrientation: 方法被调用得很好.但是, shouldAutorotate 方法不会触发.我需要在旋转时进行一些图像交换,但没有任何迹象表明旋转即将发生.

The new supportedInterfaceOrientation: method gets called just fine. The shouldAutorotate method, however, will not fire. I need to do some image swapping on rotate, but I can't get any indication that a rotation is about to occur.

提前致谢.

推荐答案

查看你的应用启动时是否出现以下错误.

See if you are getting the following error when your App starts.

应用程序窗口应该在应用程序启动结束时有一个根视图控制器

Application windows are expected to have a root view controller at the end of application launch

如果是这样,修复它的方法是在 AppDelegate.m 文件中进行以下更改(尽管似乎有很多答案如何解决这个问题):

If so the way to fix it is by making the following change in the AppDelegate.m file (although there seem to be a number of answers how to fix this):

// Replace
[self.window addSubview:[navigationController view]];  //OLD

// With
[self.window setRootViewController:navigationController];  //NEW

在此之后 shouldAutoRotate 应该被正确调用.

After this shouldAutoRotate should be correctly called.

这篇关于iOS 6 shouldAutorotate: 没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆