1

I want to have the same kind of behaviour as iMessage has for its input. I don't know in what end I should start, so I'll describe what I want to do and you can (I hope) give me suggestions on how to do this. I code in Swift so I'd like it to be in Swift if you provide any code.

What I want

I want to have a button on my screen (not an UITextView or UITextField) which upon press shows the keyboard, and where the keyboard has a UIToolBar with an UITextView in it. When I type in the UITextView the ToolBar/TextView expands up until a certain point then it starts to scroll.

How on earth do I do this? I've been trying for an hour but I can't seem to trigger the keyboard unless I have a UITextView or UITextField to set as becomeFirstResponder(). Furthermore I don't understand how I'm supposed to attach a UITextView to the UIToolBar once I get the keyboard up. I have added the UIToolBar, but not the UITextField.

Cheers

ClockWise
  • 1,509
  • 15
  • 32
  • 1
    a good start could be a search on google about it, there are also people that made control like that available on git. For instance https://github.com/muukii/NextGrowingTextView?utm_campaign=This%2BWeek%2Bin%2BSwift&utm_medium=email&utm_source=This_Week_in_Swift_79 – Andrea Mar 24 '16 at 14:06
  • See http://stackoverflow.com/questions/20108162/make-uitextview-parent-be-its-own-inputaccessoryview?s=7|1.6466 – rmaddy Mar 24 '16 at 14:40
  • I fixed this problem with childViewController. See my answer [here](https://stackoverflow.com/a/44219487/1836420). – ChikabuZ May 27 '17 at 17:00

1 Answers1

-1

This should do it for you: https://github.com/AlexLittlejohn/ALTextInputBar

It grows like you mentioned, and it's also at the bottom of screen, like an input accessory view.

  1. In your pods file copy paste

    pod 'ALTextInputBar'
    
  2. Run your podfile

  3. Configure it like this

    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
        }
    }
    
Tunaki
  • 132,869
  • 46
  • 340
  • 423
leecan999
  • 27
  • 3