为什么我的视图不会旋转?
我有一个适用于 iPad 的选项卡栏应用程序,是使用基本选项卡栏模板创建的。我添加了一些自定义视图控制器(每个选项卡一个,每个都有一个相应的 NIB)以及一些额外的视图控制器,其中 NIB 用作模式视图。一切正常,直到我旋转设备。
我的应用程序仅支持纵向,因此我在所有视图控制器中都有此功能:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIDeviceOrientationLandscapeLeft) &&
(interfaceOrientation != UIDeviceOrientationLandscapeRight);
}
但是,当颠倒时,应用程序不会在模拟器或设备中旋转。我仔细检查了所有视图控制器是否都有上述代码。
我检查了所有 NIB 并检查它们是否都勾选了“旋转子视图”。无论如何,除了让 NIB 在选项卡视图中显示所需的基本设置之外,我还没有更改任何默认设置。
我尝试将所有视图控制器中的代码更改为:
- (BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
这没有什么区别。我绝对确保所有视图控制器都使用相同的方法。我不知道我还能做什么。我看不出为什么它不应该旋转到颠倒视图。
任何对此的帮助将不胜感激。
I have a Tab Bar application for iPad, created using the basic Tab Bar template. I have added some custom view controllers (one for each tab, each with a corresponding NIB) and also some extra view controllers with NIBs to be used as modal views. Everything works great until I rotate the device.
My app only supports portrait orientation, so I had this in all my view controllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIDeviceOrientationLandscapeLeft) &&
(interfaceOrientation != UIDeviceOrientationLandscapeRight);
}
However, the app would not rotate in the simulator or the device when turned upside down. I double and triple checked that all my view controllers had the above code.
I went through all my NIBs and checked that they all have "Rotate Subviews" ticked. I haven't changed any of the NIB settings from the defaults anyway, apart from the basic things needed to get them showing in the tab views.
I tried changing the code in all my view controllers to this:
- (BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
It made no difference. I have made absolutely sure that the same method is being used in all the view controllers. I don't know what else I can do. I can see no reason why it shouldn't rotate to the upside down view.
Any help with this would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
知道了!我的一个视图控制器没有连接到 IB 中的相关选项卡。由于我还没有添加图像或为该视图控制器编写代码,所以我没有注意到它在 IB 中没有关联。我已经完成了shouldAutorotateToInterfaceOrientation方法,但似乎直到在IB中建立连接后才生效。
非常感谢您对此的建议。这是一个非常令人沮丧的问题,现在正在处理!
Got it! One of my View Controllers was not hooked up to the relevant tab in IB. As I hadn't added the images or written the code for that View Controller yet, I didn't notice that it wasn't associated in IB. I had done the shouldAutorotateToInterfaceOrientation method, but it seems that didn't take effect until the connection was made in IB.
Thanks very much for suggestions on this. That's a highly frustrating problem now dealt with!
另外,这是苹果非常有用的指南: http://developer.apple.com/library/ios/#qa/qa1688/_index.html
就我而言 - 我忘记调用 self = [super initWithNibName ....]!
Also, this is Apple's very helpful guide: http://developer.apple.com/library/ios/#qa/qa1688/_index.html
In my case - I forgot to call self = [super initWithNibName ....]!
“所有视图控制器”是否包括选项卡栏控制器?
在标签栏应用程序中,这是唯一调用和评估
shouldAutoRotateToInterfaceOrientation
的视图控制器。Does "all your view controllers" include the Tab Bar Controller?
In tab bar apps that is the only view controller who's
shouldAutoRotateToInterfaceOrientation
is called and evaluated at all.您的第一个片段在逻辑上是不正确的:
这里,
orientation
是UIInterfaceOrientation
的实例,而UIDeviceOrientationLandscapeLeft
是UIDeviceOrientation
的实例代码>.两者不是同一类型,不宜进行比较。相反,您应该使用 UIInterfaceOrientation 选项:
将方法更改为
(在我看来,当输入肯定而不是否定时,代码似乎更具可读性)
The first snippet you have is logically incorrect:
Here,
orientation
is an instance ofUIInterfaceOrientation
whereasUIDeviceOrientationLandscapeLeft
is an instance ofUIDeviceOrientation
. The two are not the same type and so should not be compared.Instead, you should use the
UIInterfaceOrientation
options:Change the method to
(the code seems to me more readable when put in the affirmative rather than negative)