2013-04-14 25 views
1

我有一個視圖控制器在我的應用程序,總是要顯示在prtaint模式。此屏幕的對象將在運行時添加並基於protaint模式。這是我的第一個視圖控制器。強制viewcontroller是肖像單點觸摸iphone

我嘗試了一些規範,如:

first

second

Third

但他們都不couldent幫助我。可以知道這個狀態的其他解決方案嗎?

我發現了一些事情有:

Monotouch - View created in landscape orientation is displayed in portrait orientation

,但我不知道如何使用這個。任何身體可以幫助嗎?

我用這個代碼

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) 
     { 
      // Return true for supported orientations 
      if (UserInterfaceIdiomIsPhone) { 
       return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown ); 
      } else { 
       return true; 
      } 

     } 


     public override bool ShouldAutorotate() 
     { 
      return true ; 
     } 
     public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation() 
     { 
      return UIInterfaceOrientation.Portrait ; 
     } 

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() 
     { 
      return UIInterfaceOrientationMask.Portrait ; 
     } 

但他們沒有工作。 。

autoroatate函數永遠不會調用:(

+0

所以你在不同的視圖中有多個方向?在你的「支持的界面方向」中你有四個勾號?只有在運行時啓動的那個你總是想要肖像,這是一個正確的假設嗎? –

+0

是的,視圖控制器是我的第一個視圖控制器在我的應用程序,我想成爲肖像,也在支持的接口方向我有四個三分之一 –

回答

1

也許您正在使用導航控制器在你的應用程序完成共進午餐模式,如果對你應該重寫UINavigation控制器,並添加你要跟自己rotaion機制來此請參閱此代碼:

public class RltNavigationController : UINavigationController 
{ 
    public RltNavigationController() : base() 
    { 
    } 

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() 
    { 
     if(this.TopViewController is HomeScreen) 
      return UIInterfaceOrientationMask.Portrait ; 
     else 
      return UIInterfaceOrientationMask.AllButUpsideDown ; 

    } 

    public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) 
    { 
     // Return true for supported orientations 
     if(this.TopViewController is HomeScreen) 
      return (toInterfaceOrientation == UIInterfaceOrientation.Portrait); 
     else 
      return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown) ; 

    } 
} 
+0

ShouldAutotrotateToInterfaceOrientation從iOS6被刪除 – cdbitesky

+0

ShouldAutorotateToInterfaceOrientation是爲ios 5設備和GetSupportedInterfaceOrientations爲ios 6和上。這兩種方法都被忽視了 –