【发布时间】:2012-05-14 14:57:52
【问题描述】:
虽然在大多数情况下,我的应用程序的方向都可以正常工作,但我在 iPad 1 上进行测试时遇到问题。如果我将设备倾斜的角度相对较低,则有时会在浏览选项卡时出现问题标签栏以横向模式出现,但页面调用纵向模式 uiview,然后尝试以横向模式呈现它,搞砸了我的 UI。
我正在尝试确定是否有一种方法可以锁定“如果标签栏以横向模式出现,则始终调用横向 UIViews,如果处于纵向模式,则始终调用纵向 UIView。”
在每个视图控制器上我都设置了以下内容:
- (void)viewDidLoad
{
[super viewDidLoad];
// iPad-specific condition here
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
self.view = self.portraitViewiPad;
}
else {
self.view = self.landscapeViewiPad;
}
}
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// iPad-specific condition here
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
//show portrait XIB here
self.view = self.portraitViewiPad;
} else {
//show landscape XIB here
self.view = self.landscapeViewiPad;
}
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// iPad-specific interface here
return YES;
}
else
{
// For iPhone and iPod touch interface
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
我还使用以下方法调整了应用程序委托,认为可以解决问题:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
//CALLS RELOAD METHODS HERE AND EACH UIVIEW IS PROPERLY BEING CALLED
}
更新:
通过检查状态栏的方向并相应地显示正确的 uiview 来更正此问题。以下是我更新 viewDidLoad 方法的方法:
if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeLeft){
NSLog(@"Left landscape detected");
self.view = self.landscapeViewiPad;
} else if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeRight){
NSLog(@"Right landscape detected");
self.view = self.landscapeViewiPad;
} else if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait){
NSLog(@"Portrait orientation detected");
self.view = self.portraitViewiPad;
} else if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown){
NSLog(@"Upsidedown Portrait detected");
self.view = self.portraitViewiPad;
}
【问题讨论】:
标签: iphone objective-c ios xcode uiinterfaceorientation