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

前端 未结 1 877
太阳男子
太阳男子 2021-01-02 16:44

I want to create attachments view, that places under input accessory view, over keyboard, like in Skype App or Viber:

I already asked such question here, bu

相关标签:
1条回答
  • 2021-01-02 17:17

    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.

    0 讨论(0)
提交回复
热议问题