Show UIView with buttons over keyboard, like in Skype,Viber messengers (Swift, iOS)

旧时模样 提交于 2019-11-30 14:16:35

Okey, thanks to Brian Nickel, i found maybe not the elegant, but very simple solution. So i had override inputAccessoryView to create a toolbar over keyboard. So basically, if i press on attach button on this toolbar, i want to see another inputView, not a keyboard. So in my custom input accessory view class i created just some textView, that is hidden:

class MessageChatInputAccessoryView : UIToolbar {
    var textView:UITextView!  //textView for entering text
    var sendButton: UIButton! //send message
    var attachButton: UIButton! // attach button "+"
    var attachTextView:UITextView! --> this one 

    override init(frame: CGRect) {
        super.init(frame: frame)
        .....
        ..... 
        attachTextView = UITextView(frame: CGRectZero)
        attachTextView.alpha = 0.0
        self.addSubview(attachTextView)
        ....
     }

So in my main view controller, i created function, the re-initialize inputView for this newly created attachTextView, something like this:

func attach(sender: UIButton) {
     if attachMenuIsShown {
          accessoryView.attachTextView.inputView = accessoryView.textView.inputView
          accessoryView.attachTextView.reloadInputViews()
          attachMenuIsShown = false
       } else {
           accessoryView.attachTextView.becomeFirstResponder()
           accessoryView.attachTextView.inputView = MessageChatAttachmentsView(frame: CGRectZero)
           accessoryView.attachTextView.reloadInputViews()
           attachMenuIsShown = true
    }

}

So when i press on attach button, my attachTextView becomes first responder, and than i re-initialize input view for this textView. And i got my attachments view right under input accessory view. And when i press attach button once again, i re-initialize inputView with default inputView for my main textView, which is keyboard view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!