InputAccessoryView docked at bottom

后端 未结 5 1585
挽巷
挽巷 2020-12-04 08:13

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 th

5条回答
  •  爱一瞬间的悲伤
    2020-12-04 08:38

    There's an excellent, easy-to-implement, open-source solution to this from the good folks at Slack: SlackTextViewController.

    Here's how to implement a view with a docked toolbar in four steps:

    1. Install the pod into your project. (http://cocoapods.org/?q=SlackTextViewController)
    2. If you're writing an app in Swift, create a header to bridge between your Swift code and their Obj-C classes. Here's a nice quick walkthrough on that. (The bridging header won't be necessary once the classes are translated into Swift, anyone want to collaborate on that?)
    3. Create a MessageViewController that inherits from SLKTextViewController, no need to write any more code than this:

      import Foundation
      import UIKit
      
      class MessageViewController: SLKTextViewController {
      
          required init(coder aDecoder: NSCoder!) {
              super.init(coder: aDecoder)
          }
      }
      
    4. In Storyboard, create a View Controller that inherits from MessageViewController.
    5. Test the app on a device or emulator, you'll see a beautiful docked textbar that also (as a bonus) expands as the user writes additional lines of text.

    Props to the team at Slack for extracting such a useful pod.

提交回复
热议问题