Reputation: 2143
I have a UITableView with custom subviews in its cells. When a user does swipe-to-delete gesture on a cell my view is shrunk for a moment while the "Delete" button is being appeared.
As I understand it happens due to some system animation which takes place when the "Delete" button is to be appeared and my subview needs to become shorter. I set my subview's contentMode to UIViewContentModeRedraw and everything looks fine after animation is finished.
I looked how this works in build-in Mail application and everything is fine there.
How can I avoid this shrinking? Is it possible to change this animation to "fade out" or something? Or can I handle a moment when this animation is started to make my subview shorter right away?
SOLUTION:
Finally I found a solution by subclassing UITableViewCell and overriding layoutSubviews method in the following way:
- (void)layoutSubviews
{
[super layoutSubviews];
UIView *view = [self.contentView viewWithTag:101];
CATransition *animation = [CATransition animation];
animation.duration = 0.2f;
animation.type = kCATransitionFade;
[view.layer removeAllAnimations];
[view.layer addAnimation: animation forKey:@"deletingFade"];
}
Thanks!
Upvotes: 1
Views: 357
Reputation: 1775
You can use this delegate method:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
// do what ever you need to change in your cell
return YES;
}
(OR)
You can utilize the following methods in TableViewCell:
- (void)willTransitionToState:(UITableViewCellStateMask)state
- (void)didTransitionToState:(UITableViewCellStateMask)state
You can change according to state if you are using customCell.
Upvotes: 2
Reputation: 5105
Override layoutSubviews
method in UITableViewCell
derived class and update positions for all your subviews accordingly to contentView.bounds.size
of the cell.
Upvotes: 1