How to make InputAccessoryView appear above UITabB

2019-07-25 09:51发布

问题:

I have a custom view that I am using as inputAccessoryView for my tableViewController.

the tableViewControlleris inside a tabBarViewController which is inside a navigation controller.

I managed to make the custom view appear correctly as the inputAccessoryView, appearing at the bottom, and when focused it goes up with the keyboard.

My problem is that it's hiding my tabBar, I searched but couldn't find anything except for a 2years old unanswered question. I want my view to appear above the tabBar, similar to the music app when having a song playing, the song and the play button and the next button appear above the tabBar not hiding it.

using swift 4.2, Xcode 10.1, iOS 11 target, testing on iOS 12.1 and 12.1.1

回答1:

I have been able to achieve this effect and made a framework called AMKeyboardFrameTracker to do just that

but first you need to understand how the inputAccessoryView work

inputAccessoryView is attached to another window called UITextEffectsWindow this window shows on top of your main app window

The main feature of using inputAccessoryView is the interactive keyboard dismissal effect with any UIScrollView because normally you can't get the keyboard frame from the native keyboard notifications callbacks

But with AMKeyboardFrameTracker I've been able to get the keyboard frame from the inputAccessoryView's superview by observing it's frame changes, so it's still using inputAccessoryView but with an empty view that has no user interaction

There is an Example in the Github repo you can download it and try it out

Note in the example app I am using a normal ViewController instead of a TableViewController if you'd like to use a TableViewController you can still achieve this by adding your CustomView to the navigationController's view