Dismiss keyboard with swipe gesture (as in Message app)

后端 未结 8 803
萌比男神i
萌比男神i 2021-01-30 17:25

When the keyboard is showing on the iPhone\'s Messages app, if the user begins a swipe down from the messages tableview and continues into the keyboard area, the keyboard will b

8条回答
  •  暖寄归人
    2021-01-30 17:39

    In swift you can use below code to get the view container of current keyboard (if exist), than you can change is's frame in your code:

    UIApplication.shared.windows
        .filter{ NSStringFromClass($0.classForCoder) == "UIRemoteKeyboardWindow" }
        .first?.subviews.filter { NSStringFromClass($0.classForCoder) == "UIInputSetContainerView" }
        .first?.subviews.filter { NSStringFromClass($0.classForCoder) == "UIInputSetHostView" }
        .first
    

    By the way here are a tool called Reveal make you can see the view hierarchical.

提交回复
热议问题