I have a custom cell with a subview inside it which on getting content from server increases in height once the response comes.
So I increase the height of this subview with animation, and on completion of the animation I send a delegate message to viewController.
in this delegate I set a instance variable with new value for the cell height and call
[tableView beginUpdates];
[tableView endUpdates];
after that which just resizes the cell with new height with smooth animation. but since this delegate method is called in the completion block of previous animation, it happens after it.
Is there a way to make both of them happen together smoothly ?
Just
1) change the subview height directly without animation,
2) set the new cellHeight of the cell in heightForRowAtIndexPath
,
and
3) update the table with animation. If do so, both the subview and the cell will animation correctly.
Use NSLayoutConstraint
..so that when a cell changes its height and width automatically its subview will also change its height and width.
NSLayoutConstraint *myConstraint1 = [NSLayoutConstraint constraintWithItem:cell
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:subView
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:-5];
NSLayoutConstraint *myConstraint2 = [NSLayoutConstraint constraintWithItem:cell
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:subView
attribute:NSLayoutAttributeHeight
multiplier:1.0
constant:-5];
[cell addConstraint:myConstraint1];
[cell addConstraint:myConstraint2];
Adjust the constant
according to your need.
Hope this will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With