How to remove a layer when its animation completes?

后端 未结 4 562
陌清茗
陌清茗 2020-12-19 13:28

I am making an iOS App. I have several CALayer objects that eventually will be deleted by a (shrinking) animation. When the animatio

4条回答
  •  情深已故
    2020-12-19 14:06

    See if this answer helps: Perform an action after the animation has finished I find animateWithDuration:animations:completion: to be way easier to use than working directly with CALayer. You can chain multiple animations via the completion handler and then remove the layer in the last one. eg:

    [UIView animateWithDuration:1.0 animations:^{
        // do first animation in the sequence
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1.0 animations:^{
            // do second animation in the sequence
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:1.0 animations:^{
                // do third animation in the sequence
            } completion:^(BOOL finished) {
                // remove layer after all are done
            }];
        }];
    }];
    

    Possibly a little messy this way, but you could refactor these into their own method calls, for instance.

提交回复
热议问题