獲取

2013-07-09 46 views
0

enter image description here獲取

我想知道如何獲得在鍵盤上輸入附件視圖的y位置一個UITextView的鍵盤的y值。誰能幫忙?

+0

嗨阿卜杜拉,你的問題[已被問及之前回答](http://stackoverflow.com/questions/10955888/ios-keyboard-location-and-orientation)。您可以通過註冊「UIKeyboard *」通知來獲取鍵盤位置。 –

+0

我試過解決方案,但我沒有得到輸入附件視圖y的位置。 –

回答

2

設置一個UITextViewDelegate並實現textViewDidBeginEditing:委託方法。當它被調用時,訪問文本視圖的inputAccessoryView屬性。然後看看視圖的frame屬性。

該框架可能位於窗口座標中。根據您的需要,您可能需要將窗口座標的框架轉換爲另一個視圖的座標。詳情請參閱UIView convertRect:...方法。

+0

謝謝!我不敢相信我沒有想到! –

0

這裏是蘋果公司的有關管理文件鍵盤:http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

觀察UIKeyboardDidShowNotification通知和查詢用戶信息字典的UIKeyboardFrameEndUserInfoKey獲取包含鍵盤的CGRect的NSValue。

更多UIKeyboardDidShowNotification這裏:http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/c/data/UIKeyboardDidShowNotification