奇怪的景观UITabBarController应用程序的启动
-
16-09-2019 - |
题
我应用程序相当简单,但是我有一些问题时,它的开始。我设置好的信息。plist至被美化,但它似乎忽略的顺序。事实上,当应用程序载荷的模拟器被美化,但随后返回在画像的模式。
这次的意见和控制器:
- MainViewController(延伸UITabBarController只是为了复盖shouldAutorotateToInterfaceOrientation:)
- 三延长UITableViewControllers为标签(还有那些有shouldAutorotateToInterfaceOrientation正确地设定)。
如果我有点力的方向的装置到景观:
[[UIDevice currentDevice]setOrientation:UIInterfaceOrientationLandscapeRight];
然后瞬间闪烁模拟器在纵向方式,然后它花.问题是,这种方式,自动转动得到启动,这是一些我无法tollerate.我只想要一个固定的,美化应用程序。
任何线索?我失去了一些东西?
解决方案
试试下面。不知道为什么它不能为你工作
1)设置关键UIInterfaceOrientation
到UIInterfaceOrientationLandscapeRight在你的.plist文件
2)复盖你的UITabBarController shouldAutorotateToInterfaceOrientation()方法;在以下代码仅涉及标签零和的一个,只有一个控制器:如果你有一个导航控制和你要控制不同的控制器,可以在该堆中,必须修改相应的代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
BOOL tabZeroController = [[[self.viewControllers objectAtIndex:0] visibleViewController] isKindOfClass:[YourTabZeroTableViewController class]];
BOOL tabOneController = [[[self.viewControllers objectAtIndex:1] visibleViewController] isKindOfClass:[YourTabOneTableViewController class]];
if(self.selectedIndex == 0 && tabZeroController)
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
if(self.selectedIndex == 1 && tabOneController)
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
return NO;
}
2)设置
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
在你的委托的applicationDidFinishLaunching()方法只是所需要的模拟器,不设备上
3)增加以下shouldAutorotateToInterfaceOrientation(方法),在你的控制器
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
4)运行设备上的应用程序,并验证其正常工作通过使用硬件的菜单项的左旋转,旋转的权利。你应该看到显示在横向模式。
不隶属于 StackOverflow