簡體   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