如何手动发送UIKeyboard通知 [英] How to manually send UIKeyboard notification

查看:104
本文介绍了如何手动发送UIKeyboard通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的uixtfields几乎没有uitextfields键盘会重叠我的屏幕底部的几个uitextfields,为了处理这个我已经实现了UIKeyboard通知,如

I have few uitextfields in my ui where keyboard will overlaps few of the uitextfields which are at bottom of my screen, to handle this i have implemented UIKeyboard notifications like

- (void)keyboardWasShown:(NSNotification*)aNotification
- (void)keyboardWillBeHidden:(NSNotification*)aNotification

我的uitextfields键盘returnKeyType是 UIReturnKeyNext 所以当用户点击下一步按钮时,我将我的下一个文本域设为 becomeFirstResponder 但是当从键盘隐藏的文本字段成为第一响应者时,其框架不会更改并更新到uikeyboard的可见区域边界,因为当我点击文本字段时通知仅首次触发。
我需要在每个becomeFirstResponder事件上触发这个keyboardWasShown方法。
提前感谢任何帮助。

and my uitextfields keyboard returnKeyType is UIReturnKeyNext so when ever user taps on Next button i'm making my next textfield as becomeFirstResponder but when the textfield which is being hidden from keyboard becomes first responder its frame is not changing and updating to visible area boundary out of uikeyboard since the notification triggers only for the first time when i tap on a textfield. I need to trigger this keyboardWasShown method on every becomeFirstResponder event. Any help is appreciated in advance.

推荐答案

首先确保这两种方法中的代码是正确的并采取考虑到当你将第一个响应者从UITextField更改为另一个时,会有两个通知sendet,一个用于键盘隐藏,一个用于键盘显示。

First make sure that your code in those two methods is correct and take in consideration that when you change the first responder from a UITextField to another there will be two notifications sendet, one for keyboard hidden and one for keyboard shown.

我不知道知道你如何处理这个通知,如果你有权访问文本字段,但我设法使用<$ c的委托方法为某些文本文件实现滚动行为$ c> UITextFields

I don't know how you handle this notification and if you have access to the text fields, but I managed to implement the scrolling behaviour for some text fileds using just the delegate methods of UITextFields

- (BOOL)textFieldShouldReturn:(UITextField *)textField (因为键盘被隐藏而向下移动内容)

-(BOOL)textFieldShouldReturn:(UITextField *)textField (move content down because the keyboard is hidden)

- (void)textFieldDidBeginEditing:(UITextField *)textField (将内容移动,因为键盘将出现)

-(void)textFieldDidBeginEditing:(UITextField *)textField (move content up because the keyboard will appear)

使用此方法即使您的文本字段已设置为inputView其他,您也可以处理内容移动像UIPickerView这样的视图。

Using this methods you can handle the content movement even if your text field has set as inputView other views like a UIPickerView.

这篇关于如何手动发送UIKeyboard通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆