2013-08-20 25 views
2

在我的應用程序中,我使用縱向導航控制器啓動secondviewcontroller,然後在第四個控制器中完成旋轉iPhone以顯示圖像。 現在的問題是: 如果目標我設置這樣的方向: enter image description hereIOS:在UINavigationController中鎖定方向

我可以用這個方法來旋轉我的形象:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 

,它做工精細,但我可以不鎖定屬於導航控制器的所有視圖,因爲它們都旋轉il縱向和橫向。

第二個選項是設置目標以這樣的方式 enter image description here

,但這種結構不檢測的方向:

鑑於將會出現:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    [self willRotateToInterfaceOrientation:orientation duration:1]; 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 

    return (interfaceOrientation == UIInterfaceOrientationPortrait); 

} 

- (BOOL)shouldAutorotate 
{ 
     return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape; 
} 

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 

     if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
     { 

     } 
     else 
     { 

     } 
    } 

    else{ 

     if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
     { 

     } 
     else 
     { 

     } 

    } 
} 

有什麼最佳方案? 感謝

回答

1

我不禁覺得,如果我讀它會救了我一段時間的文檔,但對我來說,解決辦法是 UINavigaionController並添加以下內容:

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; 
} 

由於這裏確實沒有任何實質性的事情發生,所以不需要用編碼器或其他任何東西來覆蓋init。您可以在以前引用導航控制器的任何地方引用此子類,包括Interface Builder。

+0

我在其他viewcontroller中添加了這段代碼,我想鎖定,但方向是活動的......我該怎麼辦? – CrazyDev

0

與第一個配置一起去。並對所有視圖控制器實施方法

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

。僅允許所需視圖控制器的橫向。

+0

不,這是不可能的...首次配置的旋轉是自動的 – CrazyDev