2011-07-06 32 views
1

我有一個UIToolbar設爲inputAccessoryViewUITextView。這將在編輯時顯示鍵盤頂部的工具欄。但是,在旋轉設備時,我遇到了一個問題:工具欄應該稍微高一些(32像素vs 44)。當我剛更新工具欄的高度,給我的工具欄和鍵盤之間的一個小空格:鍵盤上的UIToolbar:更改框架?

image http://i54.tinypic.com/1z6bhut.png

所以我用-didRotateFromInterfaceOrientation:同時更新的由來,然後從縱向旋轉時工作景觀。當旋轉的回漲,然而,該工具欄是12像素太低,鍵盤重疊:

image http://i56.tinypic.com/2eey2cl.png

屆時,原點(0,0)再次設置爲負值沒有幫助。有關如何使其工作的任何建議,以便工具欄更改其大小並永不重疊?

回答

1

我通過在-willRotateToInterfaceOrientation:duration:[textView becomeFirstResponder]-didRotateFromInterfaceOrientation:中調用[textView resignFirstResponder]來修復它。該系統似乎正確調整框架。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    didShowKeyboard = [self.textView isFirstResponder]; 

    [self.textView resignFirstResponder]; 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    CGRect toolbarFrame = [self.navigationController.toolbar bounds]; 
    self.keyboardToolbar.frame = toolbarFrame; 

    if (didShowKeyboard) 
     [self.textView becomeFirstResponder]; 
} 
0

除了計算原點和大小,您可以使用「自動調整大小」在旋轉期間呈現控件。

請參見本教程http://www.bogotobogo.com/XcodeSDK-Chapter4.html

我認爲這可以給你一個提示。

+0

我試着在工具欄和'inputAccessoryView'上使用Autoresizing,但它沒有工作..我也試過視圖交換,但得到了奇怪的結果。你將如何交換一個工具欄與另一個?只是更新'inputAccessoryView'並沒有幫助,也沒有'[toolbar removeFromSuperview]'。 – fabian789