问题。我的应用程序出现了一个非常奇怪的错误。我有一个带有多个选项卡 View Controller 的 UITabBarController。在 View Controller 中,我通过 shouldAutorotateToInterfaceOrientation:
实现了自动旋转在我进行以下更改之前它一直运行良好。
我在 View Controller 中实现了滑动手势以在选项卡之间切换。这是通过以下代码完成的。
- (void)onSwipeLeft {
int _count = [[self.tabBarController.tabBar items] count];
int i = self.view.tag - 1;
if (i < _count - 1) {
self.tabBarController.selectedIndex = (i + 1) % _count;
}
}
对于 onSwipeRight
同样如此.
现在,自动旋转仅在您向左或向右滑动之前有效。之后,shouldAutorotateToInterfaceOrientation:
根本不会被调用。
另见。
在this thread描述了相同的问题。我也有时候看到 类似以下的日志消息:
-[UIWindow beginDisablingInterfaceAutorotation] overflow on <UIWindow: 0x1410e0; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x141190>>. Ignoring.
我找不到关于此的任何其他信息。This question似乎在描述同一个问题。
This question似乎在描述类似的问题,但使用
popViewController:
.请注意,该错误自 SDK 3.2 以来一直存在。
怎么办? 这似乎是 SDK 中的一个错误,它在 4.1 中仍然存在。有没有人找到解决方法?这似乎是一个常见的场景。
最佳答案
我早该想到这一点。
创建UIWindow+ensureAutorotation.h
:
#import <UIKit/UIKit.h>
@interface UIWindow (ensureAutorotation)
- (void)beginDisablingInterfaceAutorotation;
- (void)endDisablingInterfaceAutorotation;
@end
和UIWindow+ensureAutorotation.m
:
#import "UIWindow+ensureAutorotation.h"
@implementation UIWindow (ensureAutorotation)
- (void)beginDisablingInterfaceAutorotation {}
- (void)endDisablingInterfaceAutorotation{}
@end
// of course this can be added as a simple category, rather than .h .m files
关于iphone - 设置 UITabBarControllers 的 selectedIndex 属性后禁用自动旋转(SDK 错误?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4738961/