On Apr 16, 2012, at 4:09 PM, Rick Mann wrote:
Hi. I'm implementing a messaging UI similar to the one found in Messages. In
that app, when you focus on the input field, the keyboard pops up, and the
input field scoots up as the keyboard comes up.
The conversation history area resizes to make room, but if you're scrolled to
the bottom, the bottom of the content remains visible; it scoots up with the
bottom edge of the conversation frame.
I tried implementing this by animating the content offset by the same amount as
the frame is resized, but it doesn't work quite right. It seems that my
UITableView's frame is not being animated to its new position, but rather it
snaps up there. Note that it resizes as a consequence of the frame bindings,
and I'm actually resizing the containing view.
Questions:
1) Is there an easier way to pin the contents of a table view to be scrolled to
the bottom during a resize animation than to also animate the contentOffset?
You can do this by wrapping the operation in your own animation block. This
simple code demonstrates doing it on 44 point high rows:
[UIView animateWithDuration:0.3 animations:^(void) {
[tableView beginUpdates];
CGPoint contentOffset = tableView.contentOffset;
if (contentOffset.y > 0) {
contentOffset.y += 44;
tableView.contentOffset = contentOffset;
}
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath
indexPathForRow:__numRows inSection:0]]
withRowAnimation:UITableViewRowAnimationAutomatic];
__numRows++;
[tableView endUpdates];
}];
2) When animating a frame change, are subframe re-sizes also animated? It looks
like they're partly immediately update, then animating.
Any subviews which are resized in the scope of the superview's frame change
will share the animation, which includes anything that has autoresizing masks.
You may need to invoke -layoutIfNeeded within your animation block on views who
defer resizing of their subviews until layout time to capture some things in an
animation. But that discussion is orthogonal to your stated goal, which can be
achieved by following the sample I've provided above.
Luke
--
Rick
_______________________________________________
Cocoa-dev mailing list
([email protected]<mailto:[email protected]>)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at
cocoa-dev-admins(at)lists.apple.com<http://lists.apple.com>
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com
This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]