我已经覆盖了初始应用视图的导航控制器,以便将视图设置为以纵向模式加载而不是旋转(应用中的其他视图会旋转以显示纵向和横向视图 - 但这个初始视图不会。):
@implementation CustomNavigationController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// return NO;
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationMaskPortrait);
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
// Return a bitmask of supported orientations. If you need more,
// use bitwise or (see the commented return).
return UIInterfaceOrientationMaskPortrait;
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
// Return the orientation you'd prefer - this is what it launches to. The
// user can still rotate. You don't have to implement this method, in which
// case it launches in the current orientation
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate {
return NO;
}
这在初始加载时效果很好,但我的问题是在应用程序中,其他视图可能会在横向方向上看到。如果用户访问其中一个横向视图,然后从此视图返回到初始应用程序主页,则初始主页将以横向方式显示(我需要此视图始终为纵向)。
有没有办法强制初始视图返回纵向,viewDidAppear总是将视图返回到纵向?
谢谢,
马特