繁体   English   中英

iOS6中的View Controller Orientation问题

[英]View Controller Orientation issue in iOS6

我的Root View Controller处于纵向模式。 我在此Root View Controller上有一个按钮,并且按钮操作代码如下所示:

-(IBAction)VideosView
{
    VideosDetailViewController *videoview=[[VideosDetailViewController alloc] initWithNibName:@"VideosDetailViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:videoview animated:YES];
    [videoview release];
}

我希望我的VideosDetailViewController处于横向模式。 为了解决这个问题,我尝试了很多方法,但没有一种方法适合我。 到目前为止,这是我尝试过的:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeLeft;
}

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
 }

但这对我不起作用。 有什么建议么?

只有根视图才能在iOS6中设置受支持的界面方向,在这种情况下,您的根视图是导航控制器,因此,甚至不会调用VideosDetailViewController中的supportedInterfaceOrientations方法。

解决此问题的一种方法是使用以下方法在UINavigationController上创建类别。 然后将查询您的VideosDetailViewController或导航控制器中的任何当前视图。

-(BOOL)shouldAutorotate {
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations {
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

您可以使用此方法解决您的问题。 它用于自动旋转功能。

-(NSUInteger) supportedInterfaceOrientations
{
   return [self.topViewController supportedInterfaceOrientations];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM