textFieldDidBeginEditing过早调用 [英] textFieldDidBeginEditing is called prematurely

查看:128
本文介绍了textFieldDidBeginEditing过早调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我必须在键盘显示的情况下向上滚动。
来获取键盘尺寸,我正在注册 UIKeyboardWillShowNotification 事件,如下所示:

I have an application in which I have to scroll up in case of the keyboard showing. to get the keyboard size, I'm registering the UIKeyboardWillShowNotification event like so:

   [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardWillShow:)
     name:UIKeyboardWillShowNotification
     object:self.view.window]

这确实有效,问题是,在调用 textFieldDidBeginEditing 之后调用它。所以,我无法获得实际的键盘大小,但只有在该字段已经处于编辑模式之后,才能在第一时间内完成注册此事件的全部目的。
我确定我已经打电话给 UIKeyboardWillShowNotification 而不是 UIKeyboardDidShowNotification ,虽然切换这两个会产生相同的结果:
第一次打电话到委托方法,然后到通知方法。关于如何扭转局面的任何想法?目前我很难编码大小,这是非常糟糕的做法...

This does work, the problem is, it is being called after the textFieldDidBeginEditing was called. So, I can't get the actual keyboard size, but only after the field is already in edit mode, which defeats the whole purpose of registering this event on the first place. I'm sure I've called the UIKeyboardWillShowNotification and not the UIKeyboardDidShowNotification, although switching these two yield the same results: first call was made to the delegate method and only then to the notification method. Any idea on how to turn this around? Currently I'm hard coding the size, which is very bad practice...

推荐答案

我可以建议一个GitHub存储库

May I suggest a GitHub repository

https://github.com/hackiftekhar/IQKeyboardManager

这篇关于textFieldDidBeginEditing过早调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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