2014-10-30 63 views
0

我正在爲iOS8構建自定義鍵盤。 我想讓我的鍵盤支持縱向和橫向模式。 如何確定設備方向? 在自定義鍵盤中獲取設備方向並不適用。如何確定自定義鍵盤中的設備方向

+0

究竟是什麼問題?你面臨什麼問題? – nurxyz 2014-11-02 22:53:29

+0

當我的鍵盤處於橫向模式時我將如何確定鍵盤擴展模塊處於橫向模式。 – Bis 2014-11-05 14:05:36

+0

我編輯了你的問題並回答了它。希望我幫助 – nurxyz 2014-11-05 19:16:24

回答

0

不幸的是,用於確定設備方向的標準方法在iOS8自定義鍵盤中不起作用。

您可以通過檢查設備的寬度和高度之間的比率來確定設備方向。 高度>寬度=肖像 寬度>高度=景觀

0

您可以使用此方法:

typedef NS_ENUM(NSInteger, InterfaceOrientationType) 
{ 
    InterfaceOrientationTypePortrait, 
    InterfaceOrientationTypeLandscape 
}; 

- (InterfaceOrientationType)orientation 
{ 
    InterfaceOrientationType result; 

    if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height) 
    { 
     result = InterfaceOrientationTypePortrait; 
    } 
    else 
    { 
     result = InterfaceOrientationTypeLandscape; 
    } 

    return result; 
} 
+0

它不能在自定義鍵盤上下文中工作 – nurxyz 2014-11-09 17:20:28

+0

如何獲取自定義鍵盤的當前模式? – Bis 2014-11-10 08:31:38

1

willRotateToInterfaceOrientationdidRotateFromInterfaceOrientation可以使用,儘管它們在iOS的8它們的替換,willTransitionToTraitCollection,ISN棄用盡管可能是因爲特徵集合沒有爲鍵盤改變而被要求旋轉。