“iMessage”和“Facebook Messenger”等应用程序允许用户通过向下滑动将键盘移出屏幕。我可以使用 CustomGestureRecognizer 设置其他 View 在屏幕上移动。 (下面的片段)
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent) {
let window = view?.window
if state == .Failed {
return
} else if let loc = touches.first?.locationInView(window) {
displacement = loc.y - swipeStartingY
delegatePass?.didSlowSwipe(displacement)
state = .Changed
}
super.touchesMoved(touches, withEvent: event)
}
How do these apps set the frame.origin.y of the keyboard to move it down and off the screen?
--已解决
How do I get my UITextView that sits above the keyboard to follow the keyboard, now that
scrollView.keyboardDismissMode = .Interactive
?
最佳答案
一旦收到来自手势识别器的回调,循环遍历所有 View 以查找哪个 View 是响应者(也称为当前正在编辑的 View )并调用方法“view.endEditing(true)”以使键盘解雇。
Facebook Messenger 应用程序刚刚结束文本字段的编辑,导致键盘关闭。
关于iOS - 使用 CustomGestureRecognizer 设置键盘位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37949767/