- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我遇到了“keyboardWillShow”触发两次,但“keyboardWillHide”调用一次的问题。
这里是 an example一旦“keyboardWillShow”触发,我就会在其中打印键盘尺寸。我还在“viewDidLoad”中放置了断点,观察者只注册了一次。我添加了两个元素“UITextField”和“UITextView”,两者的行为相同。
我正在使用 iOS 9.2、swift lang.、xcode 7
在我的 ViewController 下
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
print("keyboardWillShow sizes: \(keyboardSize)")
}
}
func keyboardWillHide(notification: NSNotification) {
print("HideHideHide")
}
}
更新
第一次它触发一次尺寸:keyboardWillShow 尺寸:(0.0, 568.0, 320.0, 253.0)
其余的两次,大小不同:(第二个 y 位置改变了,高度也改变了)keyboardWillShow 尺寸:(0.0、568.0、320.0、216.0)keyboardWillShow 尺寸:(0.0, 352.0, 320.0, 216.0)
最佳答案
可能您订阅了多个 UIKeyboardWillShowNotification
而忘记取消订阅。
尝试在 viewWillAppear
中添加观察者,并在 viewWillDisappear
中移除观察者。
关于ios - keyboardWillShow 开火两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35696344/
我使用 django celery 和 rabbitmq 作为我的经纪人( guest 兔子用户在本地机器上具有完全访问权限)。我有一堆项目都在他们自己的 virtualenv 中,但最近其中 2 个
我正在 Angular 中构建一个守卫,我需要在其中发出两个不同的 HTTP 请求,并根据这两个请求来确定是否继续。我注意到 forkJoin 是执行此操作的正确方法,但我无法触发。 在我的代码中,我
我刚刚下载了 openfire 3.10。 安装正常。但是当我启动 Openfire 服务器时,它在启动过程中出现以下错误: java.lang.IllegalArgumentException: I
我正在构建一个网络聊天应用程序。我想在每次按下“输入”按钮后存储两方之间的消息或对话。我正在使用 Openfire 服务器和 MySQL 数据库。我没有从存储对话的数据库中看到任何表格。 有插件吗?谢
我有一个 Vue 组件,我需要 body 元素有 overflow:none 但其余页面应该有 overflow:auto。因为正文位于组件外部,所以组件内的作用域 css 不会应用于正文。我的解决方
我有一个 Angular 2.0.1(最终版)应用,它使用 HashLocationStrategy 作为路线导航策略。 我定义了一条路线如下: { path: 'shiftmanag
我是一名优秀的程序员,十分优秀!