当alertController(actionSheet)出现时,inputAccessoryView会动画 [英] inputAccessoryView animating down when alertController (actionSheet) presented

查看:128
本文介绍了当alertController(actionSheet)出现时,inputAccessoryView会动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个聊天应用程序的inputAccessoryView,它始终保持可见状态,并停在屏幕底部,用于文本输入,类似于大多数消息收发应用程序.

I have an inputAccessoryView for a chat app that always remains visible and docked at the bottom of the screen for text input similar to most messaging apps.

当我呈现带actionSheet样式的alertController时,在呈现警报时,inputAccessoryView会在屏幕外动画,然后在解除警报时再次备份.这又会滚动我的tableView,这是不可取的.

When I present an alertController with actionSheet style, the inputAccessoryView animates down off screen as the alert is presented and then back up again when the alert is dismissed. This in turn scrolls my tableView and is undesirable.

之所以发生这种情况,是因为当出现警报时,聊天viewController放弃了firstResponder.

This is happening because the chat viewController is giving up firstResponder when the alert is presented.

反正有没有呈现一个alertController而不放弃firstResponder,或者当它的视图resignsFirstResponder时总有一个inputAccessoryView停靠在屏幕底部吗?

Is there anyway to present an alertController and not give up firstResponder, or anyway to keep an inputAccessoryView docked at the bottom of the screen when it's view resignsFirstResponder?

推荐答案

InputAccessoryView位于ViewController层次结构的外部-包含在UITextEffectsWindow中,该UITextEffectsWindow的rootViewController是UIInputWindowController.同样,键盘包含在UIRemoteKeyboardWindow和它自己的UIInputWindowController中.

The InputAccessoryView sits outside of your ViewController's hierarchy - it's contained in the UITextEffectsWindow whose rootViewController is a UIInputWindowController. Similarly the keyboard is contained in UIRemoteKeyboardWindow and its own UIInputWindowController.

因此,如果我们从最上面的窗口或更高的窗口(UITextEffectsWindowUIRemoteKeyboardWindow)显示警报,则它不会辞职第一响应者.

So, if we present the alert from the topmost window or higher (UITextEffectsWindow or UIRemoteKeyboardWindow), it won't resign first responder.

我找到的最简单的解决方案是:

The simplest solution I've found is:

let topViewController = UIApplication.shared.windows.last!.rootViewController! topViewController.present(alert, animated: true, completion: nil)

理想情况下,您可以安全地处理这些可选内容.一个可能更好的解决方案(我已经从以前的解决方案中看到了一些控制台错误)将是创建一个具有更高WindowLevel的新UIWindow,使其成为关键窗口并可见,然后从那里显示警报.

Ideally you would safely handle those optionals. A potentially better solution (I've seen some console errors from the previous solution) would be to create a new UIWindow with a higher WindowLevel, make it the key window and visible, and present the alert from there.

这篇关于当alertController(actionSheet)出现时,inputAccessoryView会动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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