我被一个让我抓狂的问题缠住了!我有一个以TabBarViewController开头的iPad应用程序。每个标签都有它自己的ViewController和nib-file。
为了使界面定向成为可能,我将所有定向添加到我的info.plist中,并将我的TabBarController子类化为set:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}如果我旋转界面,每个视图都会自动调整大小和格式,以便显示正确的方向。如果我在模拟器中测试它,一切看起来都很好,我可以在方向之间旋转。
现在让我抓狂的是:
如果我在肖像模式下启动应用程序,一切正常。但如果我在横向启动,我得到一个错误,我的界面方向似乎仍然是纵向,而模拟器是在横向模式!!
错误:
2011-05-24 21:50:15.011 Project[57995:207] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.我像这样检查了一下方向:
-(void)viewWillAppear:(BOOL)animated{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
NSLog(@"Orientation: Landscape");
}
else{
NSLog(@"Orientation: Portrait");
}
}日志显示,如果我在Landscape模式下启动,它是在"Landscape“模式,但如果我切换到另一个选项卡,它看起来很糟糕,因为视图显示为纵向模式。更改回我请求方向…的start-view日志显示“肖像”…但是模拟器仍然是风景!
我搞不懂为什么start的方向是纵向的,…即使我从横向…开始
你知道怎么解决这个问题吗?
发布于 2011-05-25 23:27:38
我解决了这个问题!
只需在我所有视图的viewWillAppear方法中使用它,以使其在横向模式下启动时可以工作:
if(([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeRight)){
//Landscape View
}
else{
//Portrait View
}对我来说很好!
发布于 2011-05-25 04:49:32
好的。所以文档中说viewWillAppear:是在所有动画之前调用的。当你的应用程序启动时,它的初始方向是Portrait。根据您的方向,它将旋转到该方向。因为它的动画效果是屏幕外的方向,所以必须在viewWillAppear:/之后调用,所以当viewWillAppear:被调用时,它仍然在Portrait中。这是我自己测试的。
https://stackoverflow.com/questions/6116248
复制相似问题