iOS - 使用 CustomGestureRecognizer 设置键盘位置

标签 ios swift keyboard uigesturerecognizer

“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/

相关文章:

c# - 用C#更改按下的键

ios - UISegmentedControl 边框/高亮状态

ios - 为什么有时会重用对象标识符?

ios - Firebase iOS SDK - 缺少数据库 URL

ios - 在 swift 中使用新的 Podfile 时如何忽略警告?

xcode - 如何在 Macbook pro 的德语键盘上使用 Xcode "move-line-up"快捷方式?

android - 键盘出现时隐藏ImageView,键盘消失时显示

ios - 仅在横屏状态下向左滑动

ios - 使用 MKMapCamera 的最佳方式是什么

ios - 尝试使用 PHLivePhotoView objective-c 显示实时照片时图像元数据无效