获取

2013-07-09 41 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