【发布时间】:2013-12-16 08:08:08
【问题描述】:
我的应用程序中的方向有问题。假设我有两个视图(带有专用视图控制器):
- 首先应该纵向显示(显示正确)
- 秒应该横向显示(显示不正确)
它被缩小并以纵向显示(如下面的第二张图片所示)。 当我将设备水平旋转并返回纵向时,一切正常。但是在推送视图后它显示不正确(下图)。我该如何解决这个问题?
我使用继承自 UINavigatorControler 并实现三个方法的 CustomNavigationController:
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
return [self.topViewController shouldAutorotateToInterfaceOrientation:orientation];
}
在应用程序委托中,我以这种方式初始化控制器:
self.navigationController = [[CustomNavigationController alloc] initWithRootViewController:self.viewController];
[self.window setRootViewController:self.navigationController];
第一个视图控制器以这种方式实现方向功能:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
if (orientation == UIInterfaceOrientationPortrait)
return YES;
return NO;
}
第二个视图控制器以这种方式实现方向功能:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
if (orientation == UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
【问题讨论】:
标签: ios iphone objective-c view orientation