- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要在键盘可见后立即向上移动 UIView。但我现在面临的问题是,当我使用自定义键盘(例如 SwiftKey)时,我的 UIKeyboardWillShowNotification
被调用了三次,这导致动画效果不佳。
有没有办法只处理最后一个通知?我可以轻松躲避第一个,因为高度为 0,但第二个看起来像一个有效高度,我找不到如何解决这个问题的答案。
这是我到目前为止的内容:
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillAppear:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillDisappear:", name: UIKeyboardWillHideNotification, object: nil)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func keyboardWillAppear(notification: NSNotification){
print("keyboard appear")
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() {
print("with height: \(keyboardSize.height)")
if keyboardSize.height == 0.0 {
return
}
self.txtViewBottomSpace.constant = keyboardSize.height
UIView.animateWithDuration(0.4, animations: { () -> Void in
self.view.layoutIfNeeded()
})
}
}
func keyboardWillDisappear(notification: NSNotification){
print("Keyboard disappear")
self.txtViewBottomSpace.constant = 0.0
UIView.animateWithDuration(0.4, animations: { () -> Void in
self.view.layoutIfNeeded()
})
}
我的日志输出是:
keyboard appear
with height: 0.0
keyboard appear
with height: 216.0
keyboard appear
with height: 258.0
Keyboard disappear
那么有没有办法只处理第三个通知而“忽略”前两个?
最佳答案
将以下所有字段设置为 NO 可以解决此问题。
Capitalizaion: None
Correction: No
Smart Dashes: No
Smart insert: No
Smart Quote: No
Spell Checking: No
关于ios - KeyboardWillShowNotification 被调用三次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36033153/
我有一个 UIKeyboardWillShowNotification 和 UIKeyboardWillHideNotification 的观察者。 [[NSNotificationCenter de
我正在使用 keyboardWasShown 和 keyboardWillBeHidden 通知来滑动 View 以获取可见的 TextView 。 我有一个带有六个选项卡的 UITabBar 应用程
这是操作顺序的问题 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self
我有一个带有文本字段的自定义 UITableViewCell。单元格的文本字段设置为调用委托(delegate)函数。里面 -(BOOL)textFieldShouldReturn:(UIText
我已订阅 keyboardWillShowNotification 和 keyboardWillHideNotification 以在我的 UI 中移动。我注意到,当我通过点击“Go”按钮关闭键盘时,
我需要在键盘可见后立即向上移动 UIView。但我现在面临的问题是,当我使用自定义键盘(例如 SwiftKey)时,我的 UIKeyboardWillShowNotification 被调用了三次,这
这个问题在这里已经有了答案: can't get correct value of keyboard height in iOS8 (10 个答案) 关闭 8 年前。 我的 UI 在显示键盘时需要进
我正在 viewdidload 上创建通知UIKeyboardWillShowNotification 并在 上删除它 View 将消失 . 当键盘出现在屏幕上并按预期调用一次通知时,我锁定了屏幕。通
我不知道出了什么问题。我的导航栏中有 2 个右侧按钮,当键盘打开时,我需要 A 和 B 按钮,当键盘关闭时,我需要 A 和 C,或者可能只是 C。我这样做了。我使用 UIKeyboardWillSho
当调用键盘时,我使用 UIKeyboardWillShowNotification 上下 ScrollView 。这在大多数情况下都可以正常工作。但是,键盘有一个完成按钮,可以生成 UIAlert。没
我有一个带有“安全文本输入”的表单,我想在键盘打开时向上滚动我的 View 。 我正在收听 UIKeyboardWillShowNotification 但是当焦点位于密码字段时,会再次发送此通知并且
我会在键盘出现和消失时创建通知。 override func viewDidLoad() { super.viewDidLoad() // Creates notification w
我想在不使用可用的键盘通知的情况下获取键盘的大小。原因是我在 View 上有多个文本字段,我不需要为它们的所有 调整 View 的大小,正如我在几乎每个示例中看到的那样。我只需要调整一些文本字段/ V
我有一个非常奇怪的问题,当我按回车键时会发生这种情况,并且只有当我第一次按回车键时才会发生这种情况,每次下一次它都会按预期工作。 我有一个简单的类来管理键盘,它接受我拒绝委托(delegate)给我的
我正在使用日期选择器作为文本字段的输入 View 。在 View 中将出现我已添加 UIKeyboardWillShowNotification。 我的问题是,当要查看日期选择器时,它也会出现 Key
我正在使用 UIKeyboardWillShowNotification 来检测用户何时选择文本字段以及何时打开键盘。在 ios 8 和旧版本的 iOS 中它工作正常但今天我升级到 iOS 9 和 x
初始化部分: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
我正在使用 UIKeyboardWillShowNotification 和 UIKeyboardWillHideNotification 处理键盘框架更改。当用户通过按下“globe”键打开、隐藏键
我在 IOS 7 和 IOS 8 设备上运行相同的代码但结果不同 给定一个包含两个文本字段的屏幕 在 IOS 7 中,如果我触摸第一个字段 keyboardWillShow 会被调用,但如果我在键盘已
在我标题为handleKeyboardWillShow的函数上,我的输入文本字段的移动速度高于预期。我的目的是将文本字段固定到键盘 View 的顶部。我还将代码添加到了似乎导致问题的文本字段的创建中。
我是一名优秀的程序员,十分优秀!