在应用启动时,界面方向不会更改为横向 [英] Interface Orientation won't change to Landscape on App Launch
问题描述
我陷入一个使我发疯的问题! 我有一个以TabBarViewController开头的iPad应用程序.每个Tab都有自己的ViewController和nib文件.
为使界面方向成为可能,我将所有方向都添加到了info.plist中,并将TabBarController子类化为设置方式:
- (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");
}
}
如果在横向模式下启动日志,则日志说它处于横向"模式,但是如果我将选项卡更改为另一个选项,则它看起来很糟糕,因为视图以纵向模式显示. 回到我要求定向的开始视图时,日志显示纵向"……但是模拟器仍然是横向的!
我不知道为什么开始时方向是纵向的,… 即使我从风景开始...
有什么办法解决这个问题吗?
我解决了这个问题!
在我的所有Views的viewWillAppear方法中仅使用此方法,以使其在横向模式下启动时可以工作:
if(([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeRight)){
//Landscape View
}
else{
//Portrait View
}
对我来说很好!
i stuck on a problem that drives me crazy! I have an iPad application starting with a TabBarViewController. Every Tab has it's own ViewController and nib-file.
To make interface orientation possible I added all orientations to my info.plist and subclassing my TabBarController to set:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Every View is autoresized and formatted well for displaying the right Orientation if I rotate the Interface. If I test it in the simulator, everything looks fine and I can rotate between the Orientations.
Now the point that drives me crazy:
If I launch the App in Portrait Mode, all works fine.. but if I launch in Landscape, I get an error and my Interface orientation seems still to be Portrait, while the Simulator is in Landscape Mode!!
The Error:
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.
I checked for Orientation like this:
-(void)viewWillAppear:(BOOL)animated{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
NSLog(@"Orientation: Landscape");
}
else{
NSLog(@"Orientation: Portrait");
}
}
The Log says it is in "Landscape" Mode if I launch in Landscape, but if I change tab to another it looks terrible because the View is displayed in Portrait mode instead. On change back to the start-view where i asked for Orientation… the log displays "Portrait"… but the Simulator is still Landscape!
I can't figure out why the Orientation is Portrait on start,… even if I start in Landscape…
Any idea how to solve this problem?
I solved the problem!
Simply used this in viewWillAppear method of all my Views, to make it work when started in Landscape mode:
if(([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeRight)){
//Landscape View
}
else{
//Portrait View
}
Works fine for me!
这篇关于在应用启动时,界面方向不会更改为横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!