gpt4 book ai didi

ios4 - 以模态方式呈现 UITabBarController - 自动旋转问题

转载 作者:行者123 更新时间:2023-12-05 01:28:40 25 4
gpt4 key购买 nike

我正在尝试使用以下代码以模态方式呈现 UITabBarController:

// Declare all view controllers.
TabOne *tabOne = [[TabOne alloc] initWithNibName:@"TabOne" bundle:nil];
TabTwo *tabTwo = [[TabTwo alloc] init];
TabThree *tabThree = [[TabThree alloc] init];

// Set each view controller's delegate to self.
tabOne.delegate = self;
tabTwo.delegate = self;
tabThree.delegate = self;

// Set a title for each view controller.
tabOne.title = @"One";
tabTwo.title = @"Two";
tabThree.title = @"Three";

// Create a tab bar controller.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:tabOne,tabTwo,tabThree, nil]];

// Present the tab bar controller modally.
[self presentModalViewController:tabBarController animated:NO];

// Memory management.
[tabOne release];
[tabTwo release];
[tabThree release];

这一切都按预期工作,除了我在控制台中收到以下警告:

Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations. Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate.

我对此做了一些研究,并检查了 shouldAutorotateToInterfaceOrientation 的实现如下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

据我所知,问题在于选项卡栏 Controller 不是 Root View Controller ,但我以某种方式将此模态视图呈现到深层 View 层次结构中。它是从另一个模态视图调用的,它本身是从应用程序委托(delegate)中设置的选项卡栏调用的。

我知道这有点老生常谈了,但它让我难住了。有什么想法吗?

提前致谢。

最佳答案

我遇到过类似的问题。

UITabBarController 的方向处理有一些奇怪的行为。在设置其方向时,它会递归调用 self.selectedViewController 来决定是使用单阶段还是两阶段动画。这似乎是明智的,但问题是 self.selectedViewController 最初是 nil(特别是,如果您是第一次以模态方式显示 UITabBarController),这可能会使 Controller 感到困惑。根据 iOS 版本,nil selectedViewController 将导致 UITabBarController 认为不支持单阶段动画。

试试这个:当你第一次加载/初始化你的 UITabBarController 时,添加行

tabBarController.selectedIndex = 0;

我收到了这个警告(包括严重的视觉问题: View Controller 正在切换方向但状态栏没有),以这种方式设置索引解决了这个问题。 UITabBarController 成功调用了它选择的 View Controller ,并检测到单阶段动画。

关于ios4 - 以模态方式呈现 UITabBarController - 自动旋转问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6271978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com