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

查看:429
本文介绍了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天全站免登陆