1
雖然在大多數情況下,我的應用程序的方向正常工作,但我在iPad 1上正在測試問題。如果我的設備傾斜角度較低,同時導航標籤欄以橫向模式顯示的標籤,但頁面調用縱向模式uiview,然後嘗試在橫向模式下呈現它,搞砸了我的UI。UITabBar識別縱向或橫向
我想知道是否有一種方法來鎖定「如果標籤欄出現在橫向模式,總是調用橫向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
}
UPDATE :
通過檢查狀態欄的方向並相應地顯示正確的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;
}
如果我不做這個測試,它是如何計算初始負載的呢?通過依靠should或willRotate,只有通過轉動設備改變方向才能解決這個問題。 –
解決!謝謝。我沒有檢查currentDevice方向,而是檢查了狀態欄的方向,這與我的目的一致。 –