• <bdo id='hkl9E'></bdo><ul id='hkl9E'></ul>
    1. <legend id='hkl9E'><style id='hkl9E'><dir id='hkl9E'><q id='hkl9E'></q></dir></style></legend>

      <i id='hkl9E'><tr id='hkl9E'><dt id='hkl9E'><q id='hkl9E'><span id='hkl9E'><b id='hkl9E'><form id='hkl9E'><ins id='hkl9E'></ins><ul id='hkl9E'></ul><sub id='hkl9E'></sub></form><legend id='hkl9E'></legend><bdo id='hkl9E'><pre id='hkl9E'><center id='hkl9E'></center></pre></bdo></b><th id='hkl9E'></th></span></q></dt></tr></i><div id='hkl9E'><tfoot id='hkl9E'></tfoot><dl id='hkl9E'><fieldset id='hkl9E'></fieldset></dl></div>

    2. <small id='hkl9E'></small><noframes id='hkl9E'>

    3. <tfoot id='hkl9E'></tfoot>

      1. InputAccessoryView 停靠在底部

        时间:2023-05-17
          <tbody id='Iso6b'></tbody>
      2. <tfoot id='Iso6b'></tfoot>

          • <bdo id='Iso6b'></bdo><ul id='Iso6b'></ul>

              <i id='Iso6b'><tr id='Iso6b'><dt id='Iso6b'><q id='Iso6b'><span id='Iso6b'><b id='Iso6b'><form id='Iso6b'><ins id='Iso6b'></ins><ul id='Iso6b'></ul><sub id='Iso6b'></sub></form><legend id='Iso6b'></legend><bdo id='Iso6b'><pre id='Iso6b'><center id='Iso6b'></center></pre></bdo></b><th id='Iso6b'></th></span></q></dt></tr></i><div id='Iso6b'><tfoot id='Iso6b'></tfoot><dl id='Iso6b'><fieldset id='Iso6b'></fieldset></dl></div>

              <small id='Iso6b'></small><noframes id='Iso6b'>

            1. <legend id='Iso6b'><style id='Iso6b'><dir id='Iso6b'><q id='Iso6b'></q></dir></style></legend>
                  本文介绍了InputAccessoryView 停靠在底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试实现与 Apple 消息应用中底部文本输入栏类似的定位行为.

                  I'm trying to achieve similar positioning behavior as the bottom text input bar in Apple's Messages app.

                  我尝试了很多方法,搜索了高低,有很多类似的问题,但没有一个令人满意.

                  I have tried many approaches, searched high and low and there are many similar questions but none have been satisfactory.

                  指定:

                  1. 视图底部有一个UIToolbar
                  2. 工具栏是随着键盘的出现和消失而跟随键盘
                  3. 当键盘可见时,工具栏应位于键盘顶部
                  4. 当键盘隐藏时,工具栏保持(停靠")在视图底部

                  建议的解决方案:

                  此方案不满足第二个要求的特殊情况(工具栏随着键盘的出现和消失而跟随键盘):

                  This solution does not meet a special case of the second requirement (the toolbar is to follow the keyboard as the keyboard appears and disappears):

                  • 在 iOS 7 中,引入了 UIScrollViewKeyboardDismissMode.它启用了关闭键盘的交互式手势.随着用户平移经过键盘的顶部边缘,键盘框架逐渐跟随.此解决方案无法适应这种行为,只是让工具栏停留在其动画位置.
                  • In iOS 7, UIScrollViewKeyboardDismissMode was introduced. It enables an interactive gesture for dismissing the keyboard. As the the user pans past the top edge of the keyboard, the keyboard frame gradually follows. This solution does nothing to accomodate this behavior and just leaves the toolbar stranded at it's animated position.

                  此外,此解决方案也未能满足第三个要求的特殊情况(当键盘可见时工具栏应保持在键盘顶部):

                  In addition, this solution also fails to fulfil a special case of the third requirement (the toolbar should stay on top of the keyboard when the keyboard is visible):

                  • 旋转.此解决方案需要额外的、令人讨厌的无关代码(我们将在下一个建议的解决方案中看到)来旋转工具栏以响应设备旋转.

                  此解决方案的另一个问题:

                  Another issue with this solution:

                  • 键盘高度.使用此解决方案,工具栏不会被假定为键盘高度的一部分,因此必须编写额外的代码来支持内容的正确插入.

                  下一个建议的解决方案:

                  这个解决方案似乎是 Apple 打算支持这种行为的方式,因为它解决了手动为工具栏设置动画的所有缺点.但是这个解决方案完全忽略了第四个要求(当键盘被隐藏时,工具栏保持(停靠")在视图的底部).

                  This solution seems to be the way Apple intended to support this kind of behavior, as it solves all the shortcomings of manually animating the toolbar. But this solution completely misses the fourth requirement (when the keyboard is hidden, the toolbar stays ("docked") at the bottom of the view).

                  似乎解决方案是使用 UIResponderinputAccessoryView,但以某种方式使 inputAccessoryView 不会移动到视图下方.我正在寻找干净的代码来实现这一点.其他地方也有精心设计,几乎是高尚的尝试,但如前所述,它们不符合要求.

                  It seems the solution is to use UIResponder's inputAccessoryView, but somehow making the inputAccessoryView not move below the view. I'm looking for clean code to accomplish this. There are elaborate, almost noble, attempts elsewhere, but as mentioned, they do not meet the requirements.

                  在我的特殊情况下,我希望使用 UINavigationController 的工具栏,这会带来额外的问题,因为这不是 UINavigationController 的预期行为.无论如何,我愿意引入一些 hacky 修复来实现这一点.

                  In my particular case, I am looking to use UINavigationController's toolbar which entails additional issues as this is not intended behavior for UINavigationController. No matter, I'm willing to introduce some hacky fixes to accomplish that.

                  推荐答案

                  Jason Foreman (@threeve) 刚刚向我展示了最佳"解决方案.在您的视图控制器(是的,视图控制器)上添加 inputAccessoryView: 并返回您想要停靠在底部并使用键盘移动的视图.它只是工作.视图实际上不需要在您的视图层次结构中,它会由视图控制器自动插入.

                  I was just shown "the" solution by Jason Foreman (@threeve). On your view controller (yes, view controller) add inputAccessoryView: and return the view you want to dock at the bottom and move with the keyboard. It just works. The view doesn't actually need to be in your view hierarchy it will be inserted by the view controller automatically.

                  还实现 canBecomeFirstResponder 并返回 YES(如 Max Seelemann 所述).reloadInputViews 也可以很方便.

                  edit: also implement canBecomeFirstResponder and return YES (as noted by Max Seelemann). reloadInputViews can be handy too.

                  这篇关于InputAccessoryView 停靠在底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何从推送的控制器中获取 RootViewController? 下一篇:在Xcode导航栏控制器的标题下添加字幕

                  相关文章

                  <i id='Gx1El'><tr id='Gx1El'><dt id='Gx1El'><q id='Gx1El'><span id='Gx1El'><b id='Gx1El'><form id='Gx1El'><ins id='Gx1El'></ins><ul id='Gx1El'></ul><sub id='Gx1El'></sub></form><legend id='Gx1El'></legend><bdo id='Gx1El'><pre id='Gx1El'><center id='Gx1El'></center></pre></bdo></b><th id='Gx1El'></th></span></q></dt></tr></i><div id='Gx1El'><tfoot id='Gx1El'></tfoot><dl id='Gx1El'><fieldset id='Gx1El'></fieldset></dl></div>
                  <legend id='Gx1El'><style id='Gx1El'><dir id='Gx1El'><q id='Gx1El'></q></dir></style></legend><tfoot id='Gx1El'></tfoot>

                    <small id='Gx1El'></small><noframes id='Gx1El'>

                    • <bdo id='Gx1El'></bdo><ul id='Gx1El'></ul>