On Tue, May 24, 2016, at 05:37 PM, Alex Zavatone wrote: > > On May 24, 2016, at 4:02 PM, Kyle Sluder wrote: > > > On Tue, May 24, 2016, at 12:33 PM, Doug Hill wrote: > >> OK, this might have been more obvious to people, but it finally came to > >> me how to handle the keyboard display. > >> > >> Instead of changing the view size, I move the center of the view up, then > >> apply a content inset to the table to adjust for the part of the table > >> offscreen. Animations seem to work much better now. > > > > Did you really mean “move the center of the view”? Or did you mean > > scrolling the center of the viewport? > > > > Either way, contentInset is definitely the way to handle this. > > Just checking. You meant to use contentInset and not contentOffset?
Yes, I meant contentInset. contentOffset is just another name for self.bounds.origin. --Kyle Sluder > > I'm going to need to handle this exact issue soon too. > > Thanks, Kyle. > > Alex Zavatone > > > --Kyle Sluder > > > >> > >> Doug Hill > >> > >>> On May 20, 2016, at 5:21 PM, Doug Hill <cocoa...@breaqz.com> wrote: > >>> > >>> I’m implementing a chat message view with a table view and a text field > >>> underneath it. I want the most recent messages at the bottom, and the > >>> scroll position always to stay at the last row in the table. > >>> > >>> There are some tricks to making sure the table scrolls to the bottom when > >>> it’s first drawn and when adding new rows. I seem to be able to make this > >>> work but I’m running into a problem keeping the table scrolled to the > >>> bottom when the keyboard is shown. I listen for the 'keyboard shown’ > >>> notification and adjust the height of my entire view by the height of > >>> keyboard. This works but the scroll position ends up wrong, as it doesn’t > >>> keep the same scroll position at the last row when the view is moved up. > >>> OK, so I set the contentOffset to compensate for this. > >>> > >>> Here is the code I use in the Keyboard Will show notification: > >>> > >>> [UIView animateWithDuration:keyboardAnimDuration > >>> animations: > >>> ^{ > >>> self.view.frame = newViewFrame; > >>> } > >>> completion:^(BOOL finished) > >>> { > >>> [self.myTableView setContentOffset:newContentOffset animated:NO]; > >>> }]; > >>> > >>> So far, things work pretty well and things end up in the right place > >>> with. However, the animation is weird. > >>> > >>> • Even though the view frame is changed inside the animation block, it > >>> moves into place immediately with no animation. No matter what duration I > >>> set it seems to be ignored. > >>> • Then the keyboard scrolls into place. Because my view has already been > >>> moved up, you see a blank space where the keyboard moves up and over. > >>> This looks pretty bad. > >>> • The table scrolls with an animation even though contentOffset is > >>> changed in the completion block and I set the animated param to NO. > >>> • The time for the table scroll to animate is fixed. > >>> > >>> Here is an example of this animation: > >>> > >>> https://youtu.be/SBSts2UOJXw > >>> > >>> (Try on slow speed to see it better) > >>> > >>> I know this can be done correctly because I see other iOS chat apps that > >>> make the list view move up with the keyboard in a coordinated, smooth > >>> animation. Any ideas? > >>> > >>> Doug _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com