Change UITableView contentInset without changing its contents?

I want to create a user interface similar to the Apple Messages app on the iPhone. I have a table view and a text box below it. When I select a text box, I animate the contents of the tableInset view when the keyboard slides so that the content appears above the keyboard.

I have a code that uses a gesture recognizer to determine when the user scrolls down the table view and animate the keyboard as it happens (if you see the Apple Messages application, it has the same functions as for rejecting the keyboard. You scroll down the table view and when your finger slides past the text field, the keyboard goes down with it).

This works fine, but if the table view scrolls up and I start changing my content insertion when the keyboard slides down, the table view scrolls up and then goes back, causing a weird jerky animation. I believe this is because changing the contents of the Inset resets the contentOffset to the top of the table view if the table view scrolls from the top, and that makes it act weirdly.

Does anyone know how to change the content. Enter a scroll view without changing its contentsOffice?

+6
source share
1 answer

I managed to get everything to work fine with a small workaround. I just did this:

// in a method that gets repeatedly called as the pan gesture recognizer changes if([tableView contentOffset].y > 0) { UIEdgeInsets insets = [tableView contentInsets]; inset.bottom = currentKeyboardHeight; [tableView setContentInset:inset]; } 

so that the inserts do not change if the contentOffset was at the very top or scrolling from the top. If the table scrolls and drags a little, it will change the insert until it hits the top, and then it stops changing, so that a strange flicker does not occur.


Edit: Figured out the root cause and thought I was updating this, and not just leaving a workaround. What I did was mixing CGAffineTransformMakeTranslation in the middle of my frame calculations, which is a big no-no problem according to Apple's documentation. If the transform property is not CGAffineTransformIdentity , then the frame becomes undefined, and this caused a very strange behavior if I scroll through the table view and at the same time change its insert content.

+7
source

Source: https://habr.com/ru/post/920651/


All Articles