设置 UITabBarControllers 的 selectedIndex 属性后自动旋转被禁用(SDK bug?)

发布于 2024-10-13 07:12:34 字数 1526 浏览 3 评论 0 原文

问题。我在我的应用程序中遇到了一个非常奇怪的错误。我有一个 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] 在 >。忽略。我找不到有关此的任何其他信息。

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

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

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

The problem. I'm getting a very strange error in my application. I have a UITabBarController with several view controllers for the tabs. In the view controllers I have implemented autorotation via shouldAutorotateToInterfaceOrientation: and it was working fine until I made the following change.

I implemented swipe gestures in the view controllers to change between tabs. This is accomplished via the following code.

- (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;
  }
}

And similarly for onSwipeRight.

Now, autorotation only works until you swipe left or right. After that, shouldAutorotateToInterfaceOrientation: is never called at all.

See also.

  • In this thread the identical problem is described. I also sometimes see
    a log message like the following: -[UIWindow beginDisablingInterfaceAutorotation] overflow on <UIWindow: 0x1410e0; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x141190>>. Ignoring. I can't find any other information about this.

  • This question seems to be describing the same problem.

  • This question seems to be describing a similar problem but with popViewController:. Note that the bug has been there since SDK 3.2.

What to do? It seems like a bug in the SDK which is still present in 4.1. Has anyone found a workaround? It seems like a common scenario.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜血缘 2024-10-20 07:12:34

我应该早点想到这一点。

创建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

I should have thought of this earlier.

Create UIWindow+ensureAutorotation.h:

#import <UIKit/UIKit.h>

@interface UIWindow (ensureAutorotation)

- (void)beginDisablingInterfaceAutorotation;
- (void)endDisablingInterfaceAutorotation;

@end

And 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文