1

I'd like to use the UIViewController's input accessory view like this:

override func canBecomeFirstResponder() -> Bool {
    return true
}

override var inputAccessoryView: UIView! {
    return self.bar
}

but the issue is that I have a drawer like view and when I slide the view open, the input view stays on the window. How can I keep the input view on the center view like Slack does it.

enter image description here

Where my input view stays at the bottom, taking up the full screen (the red is the input view in the image below):

enter image description here

SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
  • If slack's view slides over, then they're probably not setting it as the `inputAccessoryView`. They're probably just managing its location “manually” in code. – rob mayoff Oct 25 '15 at 05:59
  • Yes, maybe. But if you use Slack, bring the keyboard up and slide down on the table view, the keyboard will start going down once you hit the top of the input view. That makes me think it is an input view and is not being managed manually. – SirRupertIII Oct 25 '15 at 06:25
  • Doesn't that just indicate that they set `tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag` or `UIScrollViewKeyboardDismissModeInteractive`? – rob mayoff Oct 25 '15 at 06:26
  • Yeah, they do that too, but because I'm managing my 'inputView' manually and the keyboard does not slide down once I reach the very top of my input view. It slides down once I reach the top of the keyboard. Slack's acts like a real input view because the keyboard starts sliding down as soon as I hit the top of the input view. – SirRupertIII Oct 25 '15 at 06:30
  • I actually think they grab the frame of the keyboard and change that rather than using UIScrollViewKeyboardDismissModeInteractive. https://github.com/slackhq/SlackTextViewController/blob/c49e2b80ecd52737f5c43cd831f47d74558ffa0a/Source/SLKInputAccessoryView.m – SirRupertIII Oct 25 '15 at 06:35
  • That solves my issue I guess. – SirRupertIII Oct 25 '15 at 06:36

1 Answers1

0

There are two ways to do this exactly like Slack doing it, Meiwin has a medium post here A Stickler for Details: Implementing Sticky Input Field in iOS to show how he managed to do this which he actually puts an empty UIView as an inputAccessoryView then track it’s coordinates on screen to know where to put his custom view in relation with the empty view, this way can be helpful if you are going to support SplitViewController on iPad, but if you are not interested in this way, you can see how I managed to do this like this image

Here is before swiping

Here is after

All I did was actually taking a snapshot from the inputAccessoryView window and putting it on the NavigationController of the TableViewController

I am using SideMenu from Jon Kent and it’s pretty easy to do it with the UISideMenuNavigationControllerDelegate

var isInputAccessoryViewEnabled = true {
    didSet {
        self.inputAccessoryView?.isHidden = !self.isInputAccessoryViewEnabled
        if self.isInputAccessoryViewEnabled {self.becomeFirstResponder()}
    }
}

func sideMenuWillAppear(menu: UISideMenuNavigationController, animated: Bool) {
    let inputWindow = UIApplication.shared.windows.filter({$0.className == "UITextEffectsWindow"}).first
    self.inputAccessoryViewSnapShot = inputWindow?.snapshotView(afterScreenUpdates: false)
    if let snapShotView = self.inputAccessoryViewSnapShot, let navView = self.navigationController?.view {
        navView.addSubview(snapShotView)
    }

    self.isInputAccessoryViewEnabled = false
}

func sideMenuDidDisappear(menu: UISideMenuNavigationController, animated: Bool) {
    self.inputAccessoryViewSnapShot?.removeFromSuperview()        
    self.isInputAccessoryViewEnabled = true
}

I hope that helps :)

Amr Mohamed
  • 2,290
  • 4
  • 20
  • 39