[英]iPad: How to display a different screen depending on orientation (landscape / portrait)
我有一個 iPad 應用程序,可用於所有四種視圖模式(縱向上/下和橫向左/右)。 但是在某個時刻,我有一個視圖,我只想在橫向模式下看到。 因此,我在 UIViewController 中執行以下操作,這將觸發查看僅橫向視圖的操作:
- (void) showProperty:(Property *) property {
if ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft || [self interfaceOrientation] == UIInterfaceOrientationLandscapeRight) {
PropertyViewController *propertyView = [[PropertyViewController alloc] initWithNibName:@"PropertyViewController" bundle:[NSBundle mainBundle]];
propertyView.property = property;
[self.navigationController pushViewController:propertyView animated:YES];
[propertyView release];
propertyView = nil;
}
else {
RotateDeviceViewController *rotateView = [[RotateDeviceViewController alloc] initWithNibName:@"TabRotate" bundle: [NSBundle mainBundle]];
rotateView.property = property;
[self.navigationController pushViewController:rotateView animated:YES];
[rotateView release];
rotateView = nil;
}
}
這工作正常,因此當 iPad 保持在橫向模式時顯示所需的屏幕(PropertyViewController),如果不是,它顯示 RotateDeviceViewController 向用戶顯示他/她應該旋轉設備以正確查看屏幕的消息.
因此,當用戶將他/她的設備旋轉到橫向模式時,我想向他們展示正確的視圖(PropertyViewController)。 所有這些都有效!
雖然在這個RotateDeviceViewController中出現了問題。我有以下內容:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
[self showProperty];
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
- (void) showProperty {
PropertyViewController *propertyView = [[PropertyViewController alloc] initWithNibName:@"PropertyViewController" bundle:[NSBundle mainBundle]];
propertyView.property = property;
[self.navigationController pushViewController:propertyView animated:YES];
[propertyView release];
}
因此,只要我將設備(查看RotateDeviceViewController時)旋轉到橫向模式,我就會向用戶展示PropertyViewController 。 這行得通...但是當PropertyViewController出現時,它顯示我的布局旋轉了 90 度。 所以基本上它以縱向模式顯示內容,而不是使用橫向模式(這實際上是你拿着設備的方式)..
我希望這是有道理的,有人可以告訴我是什么原因造成的。
截圖更清楚:
在此刻
- (BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation
您正在告訴視圖 controller 您支持哪些方向。 設備實際上還沒有旋轉,因此視圖控制器的intefaceOrientation
屬性仍然是portrait
的,所以當它被推入堆棧時,它認為設備是portrait
的。
pseudo code
shouldAutoRotate... // at this point self.interfaceOrientation == portrait
// you push your controller here so it loads when the property is
我不確定這是否會很好用,但我能看到的最早可以推送的是
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.