1

问题。 我的应用程序中出现了一个非常奇怪的错误。我有一个 UITabBarController 和几个用于选项卡的视图控制器。在视图控制器中,我已经实现了自动旋转,shouldAutorotateToInterfaceOrientation:并且在我进行以下更改之前它工作正常。

我在视图控制器中实现了滑动手势以在选项卡之间切换。这是通过以下代码完成的。

- (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:根本就不会被调用。

也可以看看。

  • 这个线程中描述了相同的问题。我有时还会看到类似以下的日志消息:-[UIWindow beginDisablingInterfaceAutorotation] overflow on <UIWindow: 0x1410e0; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x141190>>. Ignoring. 我找不到有关此的任何其他信息。

  • 这个问题似乎描述了同样的问题。

  • 这个问题似乎描述了一个类似的问题,但带有popViewController:. 请注意,该错误自 SDK 3.2 以来一直存在。

该怎么办? 这似乎是 SDK 中的一个错误,它仍然存在于 4.1 中。有没有人找到解决方法?这似乎是一个常见的场景。

4

1 回答 1

0

我应该早点想到这一点。

创建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
于 2011-01-19T21:42:09.867 回答