Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make InputAccessoryView appear above UITabBarViewController's tabs?

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

like image 359
user773277 Avatar asked Oct 16 '22 09:10

user773277


1 Answers

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

AMKeyboardFrameTracker.gif

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

like image 190
Amr Mohamed Avatar answered Nov 15 '22 10:11

Amr Mohamed