简体   繁体   English

iOS6中的View Controller Orientation问题

[英]View Controller Orientation issue in iOS6

My Root View Controller is in portrait mode. 我的Root View Controller处于纵向模式。 I have a button on this Root View Controller and the button action code is shown here: 我在此Root View Controller上有一个按钮,并且按钮操作代码如下所示:

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

I would like my VideosDetailViewController to be in landscape mode. 我希望我的VideosDetailViewController处于横向模式。 To solve this problem I've tried many methods but none works for me. 为了解决这个问题,我尝试了很多方法,但没有一种方法适合我。 This is what I have tried so far: 到目前为止,这是我尝试过的:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeLeft;
}

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

But this does not work for me. 但这对我不起作用。 Any suggestions? 有什么建议么?

only the root view can set the supported interface orientation in iOS6, in this case your root view is the navigation controller, so the supportedInterfaceOrientations method in your VideosDetailViewController is never even called. 只有根视图才能在iOS6中设置受支持的界面方向,在这种情况下,您的根视图是导航控制器,因此,甚至不会调用VideosDetailViewController中的supportedInterfaceOrientations方法。

one way around this is to create a category on UINavigationController with the following methods. 解决此问题的一种方法是使用以下方法在UINavigationController上创建类别。 then your VideosDetailViewController or whatever the current view in the navigation controller will be queried. 然后将查询您的VideosDetailViewController或导航控制器中的任何当前视图。

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

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

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

You can use this method for your problem. 您可以使用此方法解决您的问题。 It is for Auto Rotation functionality. 它用于自动旋转功能。

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

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

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