2016-11-07 78 views
2

我在支持橫向和縱向方向的應用程序中有一個viewcontroller鍵盤在ios中以錯誤的方向出現

在一個按鈕上單擊,出現一個彈出窗口,我應該輸入名稱。一切工作,因爲它應該在肖像模式。

enter image description here

但是,如果我取消鍵盤,向左或向右旋轉,然後打開彈出,鍵盤仍然在縱向模式下打開設備。

enter image description here

我已經shouldAutorotate返回true和supportedInterfaceOrientations返回在viewcontrollerAllButUpsideDown,所以旋轉自動發生。

我試過thisthis選項,但它們都沒有工作。

任何想法該怎麼辦?

+0

你可以顯示你處理你的方向的代碼嗎,如果使用IB創建的話,可能會顯示一些截圖嗎? – IamNguele

+0

@IamNguele我可以,但代碼是在Xamarin。如果沒有絕對的必要性,我通常會避免將Xamarin代碼放在​​我希望本機開發人員回答的問題中。不幸的是,他們不太可能會回答。 :( – arsena

+1

http://stackoverflow.com/questions/40318488/uialertcontroller-addtextfield-orientation-issue-from-ios10-on-ipad#comment68002435_40318488 - 可能是這可以幫助 - 閱讀評論 –

回答

0

好了,修好了,我的錯,我猜。

看起來Keyboard和UIViewController分別調用supportedInterfaceOrientations並根據其返回值進行旋轉。我在那裏有一個if-else聲明,並且僅在某些情況下才返回AllButUpsideDown。當鍵盤檢查是否應該旋轉方法返回Portrait,並且viewcontroller值爲AllButUpsideDown

所以我改變了這一點:

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

要這樣:

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

現在只ShouldAutoRotate決定是否轉動應該發生與否。

要一些了,應該是這樣的:

public override bool ShouldAutorotate() 
    { 
     if (someStatement) 
     { 
      return true; 
     } 
     return false; 
    } 

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() 
    { 
     return UIInterfaceOrientationMask.AllButUpsideDown; 
    } 
0

嘗試通過添加以下代碼到你的ViewController的viewDidAppear方法

- (void)viewDidAppear:(BOOL)animated 
    { 
     [super viewDidAppear:animated]; 
     [[UIDevice currentDevice] setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"]; 
     [[UIDevice currentDevice] setValue:@(self.interfaceOrientation) forKey:@"orientation"]; 

    } 
+0

不幸的是,沒有幫助 – arsena

0

我得到了我的一些視圖控制器的完全一樣的錯鍵盤的方向最近後我放棄了支持iOS 8,並撞到了部署目標到iOS 9.事實證明,當我的以前的同事使用solution here來解決基本SDK爲iOS 9時的舊問題(我們現在在10和11時從Xcode 9 beta編碼)。該解決方案(基本上將UIAlertController的supportedInterfaceOrientations覆蓋爲僅允許肖像)將強制以較新的SDK +部署目標縱向呈現鍵盤,即使應用程序窗口和警報本身處於橫向。

刪除覆蓋解決了問題,我沒有看到任何問題警報超過警報。