开发者

IOS UITableview how to take action after table animations complete

开发者 https://www.devze.com 2023-03-11 08:56 出处:网络
How can I cause action to be taken upon completion of a UITableview\'s animation? I\'m attempting to shrink a UITableview cell and remove a subview of the cell that\'s not visible after the shrinkage

How can I cause action to be taken upon completion of a UITableview's animation?

I'm attempting to shrink a UITableview cell and remove a subview of the cell that's not visible after the shrinkage. To shrink the cell, I'm calling [tableview beginUpdates] and [tableview endUpdates], and changing the height of the cell as returned by theheightForRowAtIndexPath datasource method of the UITableview.

The challenge is, i need the开发者_开发知识库 tableview to complete shrinking so the subview is out of sight before I can remove the subview. if I put the code to remove the subview from the cell right after (or before or between) the to call [tableview endUpdates] then the subview is removed too soon (it doesn't wait for the animation) and it looks funny.

My thought is i'd like to be able to setup a callback that runs upon completion of the animation, and remove the subView in the callback


What about this?

[CATransaction begin];

[CATransaction setCompletionBlock:^{
    // animation has finished
}];

[tableView beginUpdates];
// shrink the cells
[tableView endUpdates];

[CATransaction commit];


Try Using NSNotifications class. Post Notifications when something is about to happen, and later after something has happened. You can use a bool in the same notification method to toggle between 'about to happen' and 'has happened'.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号