2013-02-01 14 views
0

我有一個包含圖像和桌面視圖的視圖控制器。在此視圖控制器中,我將一個segue連接到包含全屏幕圖像的橫向視圖(當您將Apple的Stocks應用程序橫向翻轉以全屏查看圖形時使用的相同想法)。在不需要的視圖上觸發的替代景觀

這賽格瑞通過以下方法調用:

- (void)updateLandscapeView 
{ 
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) 
    { 
     [self performSegueWithIdentifier: @"toGraph" sender: self]; 
     isShowingLandscapeView = YES; 
    } 
    else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView) 
    { 
     [self dismissViewControllerAnimated:YES completion:nil]; 
     isShowingLandscapeView = NO; 
    } 
} 

除此之外,當iPhone處於縱向,我還可以向下鑽取的實現代碼如下一對夫婦更水平。問題在於:在這些相應的層次上,當我將方向轉換爲風景時,橫向視圖的延續仍會被觸發!...我該怎麼做才能使這不會發生?我只對從包含圖像的第一個視圖轉到橫向模式感興趣。

謝謝您提前!

回答

1

我不確定我的問題是否正確..但是如果您的意思是「鑽取表格視圖」以便在導航控制器層次結構中進行更深層次的設置,則可以嘗試以下操作..

這就是我的(我認爲)類似的情況做了:

的AppDelegate:

在.H

@property (nonatomic) BOOL shouldAutorotate; 

中的m:

//在didFinishLaunchingWithOptions:

self.shouldAutorotate = NO; 

//仍處於.m文件

// Autorotation handling 
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    return self.shouldAutorotate ? 
    UIInterfaceOrientationMaskAllButUpsideDown : 
    UIInterfaceOrientationMaskPortrait; 
} 

導航控制器呈現人像控制器

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    if (self.selectedViewController) 
     return [self.selectedViewController supportedInterfaceOrientations]; 

    return UIInterfaceOrientationMaskPortrait; 
} 

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

縱向視圖控制器(在這裏也是一個非常相似你有的處理):

在viewWillAppear中:

[(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldAutorotate:YES]; 

旋轉處理:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

景觀 - 視圖 - 控制器(可能是您的全屏幕圖像):

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

更深導航控制器層次結構(其中只有肖像想要):

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

看起來有些複雜,但這是唯一的方法,我設法讓這些旋轉的東西在iOS5和6都能正常工作。

+0

我認爲你理解的很好!但我不明白這是什麼代碼行的意思是:[(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldAutorotate:YES]; –

+0

這會將AppDelegate中的「shouldAutorotate」屬性設置爲「YES」。所以這應該激活自動旋轉一個縱向控制器的地方控制器的地方。 – d4Rk

+0

當我將這行代碼放在我的項目中時,它告訴我「使用未聲明的標識符:AppDelegate」,我錯過了什麼?我很抱歉打擾你,但我仍然是一個菜鳥編程。 –