使用拖动关闭时如何使 inputAccessoryView 留在屏幕上? [英] How do I make inputAccessoryView stay on screen when using drag to dismiss?

查看:57
本文介绍了使用拖动关闭时如何使 inputAccessoryView 留在屏幕上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道视图控制器必须是 firstResponder 以便 inputAccessory 保持在底部.我正在使用自定义 inputView/键盘.我可以通过删除 inputView 但不辞职第一响应者来使用完成按钮手动关闭它.但是,当我启用交互式拖动以在我的滚动视图上关闭时,代码会自动退出第一响应者.那么我怎样才能使用交互式拖动来关闭并保持我的视图控制器作为第一响应者呢?以前有人做过这个吗?我想也许这是不可能的,我可能需要使用手势识别器制作我自己的交互式拖动来消除.

I know that the view controller must be firstResponder in order for the inputAccessory to stay at the bottom. I am using a custom inputView / keyboard. I can manually dismiss it with a done button by removing the inputView but not resigning first responder. However when I enable the interactive drag to dismiss on my scrollview, the code automatically resigns first responder. So how can I use the interactive drag to dismiss and yet keep my viewcontroller as first responder? Anyone done this before? I thought maybe it is not possible and that I may need to make my own interactive drag to dismiss using a gesture recognizer.

更多信息:我有一个按钮,可以在标准键盘和我的自定义键盘之间切换.我已经看到驳回这些原因 2 键盘确实驳回了通知.我以为我可以在 keyboardDidHide 方法中成为 firstResponder ,但这并不奏效,因为我无法区分手动关闭键盘的时间和交互式拖动的时间.这很重要,因为当我手动关闭时,我不需要重新加载输入视图或成为第一响应者,因为我已经处理了它.

More info: I have a button that swaps between standard keyboard and my custom one. I have seen dismissing these cause 2 keyboard did dismiss notifications. I thought I could become firstResponder in the keyboardDidHide method but this didn't work well since I couldn't tell the difference between when I manually dismissed the keyboard and when the interactive drag does it. This matters because I don't need to reload the input view or become first responder when I manually dismiss because I took care of it already.

任何建议都会很棒.我正在尝试在 UIViewController 级别使用 inputView 和 inputAccessoryView.

Any suggestions would be amazing. I am trying to use inputView and inputAccessoryView on the UIViewController level.

推荐答案

经过一天的折腾,我有了答案.

Well after a day of pulling my hair, I have an answer.

使用我的视图控制器的 canResignFirstResponder 成功了.在 viewWillAppear 我设置了一个 BOOL responderOverride = YES;

Using the canResignFirstResponder of my viewcontroller did the trick. In viewWillAppear I set a BOOL responderOverride = YES;

viewWillDisappear中调用

responderOverride = NO;[self resignFirstResponder];

当滚动视图上的交互式拖动尝试 resignFirstResponder 时,canResignFirstResponder 返回 no,这会阻止我的视图控制器退出并保持我的输入附件保留并位于屏幕底部.

When the interactive drag on the scrollview tries to resignFirstResponder, canResignFirstResponder returns no which prevents my viewcontroller from resigning and keeps my input accessory retained and sitting at the bottom of the screen.

还有很多其他代码可以重新加载输入视图,但由于真正的问题是如何强制控制器保持第一响应,这样我们才不会丢失输入附件视图,那么此解决方案有效.

There is a lot of other code with reloading input views but since the real question was how to force a controller to stay first responder so we don't lose our input accessory view, then this solution works.

这篇关于使用拖动关闭时如何使 inputAccessoryView 留在屏幕上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆