【问题标题】:UITextView as inputAccessoryView like iMessageUITextView 作为 inputAccessoryView 就像 iMessage
【发布时间】:2016-03-24 13:55:56
【问题描述】:

我希望具有与 iMessage 的输入相同的行为。我不知道我应该从什么开始,所以我会描述我想做什么,你可以(我希望)给我关于如何做到这一点的建议。我使用 Swift 编写代码,所以如果您提供任何代码,我希望它使用 Swift。

我想要什么

我想在我的屏幕上有一个按钮(不是UITextViewUITextField),按下它会显示键盘,并且键盘上有一个UIToolBar 和一个UITextView。当我输入UITextView 时,ToolBar/TextView 会向上扩展直到某个点然后开始滚动。

我到底该怎么做呢?我已经尝试了一个小时,但我似乎无法触发键盘,除非我将UITextViewUITextField 设置为becomeFirstResponder()。此外,我不明白一旦我拿起键盘,我应该如何将UITextView 附加到UIToolBar。我添加了UIToolBar,但没有添加UITextField

干杯

【问题讨论】:

标签: ios swift keyboard toolbar


【解决方案1】:

这应该为你做:https://github.com/AlexLittlejohn/ALTextInputBar

它像你提到的那样增长,它也在屏幕底部,就像一个输入附件视图。

  1. 在你的 pods 文件中复制粘贴

    pod 'ALTextInputBar'
    
  2. 运行你的 podfile

  3. 这样配置

    import ALTextInputBar
    
    class ViewController: UIViewController {
    
        let textInputBar = ALTextInputBar()
    
        // The magic sauce
        // This is how we attach the input bar to the keyboard
        override var inputAccessoryView: UIView? {
            get {
                return textInputBar
            }
        }
    
        // Another ingredient in the magic sauce
        override func canBecomeFirstResponder() -> Bool {
            return true
        }
    }
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多