2011-05-12 68 views
0

我試圖將自定義鍵盤附加到UITextField,並且鍵盤會響應不同的視圖方向(橫向,縱向等)。總之,問題是,當鍵盤確實出現時,當我旋轉設備時響應視圖方向時,鍵盤的尺寸全部搞亂了,我不太清楚如何設置鍵盤框架/邊界正確。希望這裏的某個人能幫我一把!UITextField自定義鍵盤和對設備方向的響應

這裏是我的設計:

鍵盤從UIViewController中(從廈門國際銀行)的一個子建。有兩個視圖:landscapeKeyboardView和portraitKeyboardView。

鍵盤通過屬性「inputView」附加到UITextField。

鍵盤視圖的旋轉的函數來完成:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationduration:(NSTimeInterval)duration 
{ 
    if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) 
    { 
     self.view = self.landscapeKeyboardView; 
    }else if((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) 
    { 
     self.view = self.portraitKeyboardView; 
    } 
} 

旋轉確實發生,但鑑於尺寸是旋轉後全亂了。我也嘗試手動設置框架或self.view或landscapeKeyboardView或portraitKeyboardView的視圖的界限,他們都沒有解決問題。

有誰知道如何解決這個問題?還是有更好的自定義鍵盤設計模式?

謝謝!

回答

0

您可能需要翻譯CGRect進行輪換。 UIView有許多實例方法來轉換rects和points。它考慮了另一個視圖框架之外的視圖(例如,找出鍵盤矩形的UIPopover下方多遠)以及旋轉。 c onvertRect:fromView:只是一個例子,但它們都以'convert'開頭。