How to use UIBezierPath with CoreAnimation?

前端 未结 3 1555
小蘑菇
小蘑菇 2021-01-15 10:30

I am using this code to remove animate my UIView to the delete button on delete button press. Here\'s the code :

UIBezierPath *movePath = [UIBezierPath bezi         


        
相关标签:
3条回答
  • 2021-01-15 11:01

    Try changing the opacity animation to:

    CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];

    and then set the animation group's removeOnCompletion to NO and its fillMode to kCAFillModeForwards like Noah Witherspoon suggested.

    0 讨论(0)
  • 2021-01-15 11:06

    Animations apply to the presentation layer, not the model layer. You need to apply your changes to both. That's a fancy way of saying that when you do animate something, you also need to set it directly.

            ...
            [icon.layer setPosition:CGPointMake(senderView.center.x, icon.center.y)];
            [icon.layer setTransform:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
            [icon.layer setAlpha:0.1];
    

    (Note that you may want to animate the view's center here rather than the layer's position.)

    Chapter 7 of iOS 5 Programming Pushing the Limits has pages and pages on this if you want all the gory details. Here's the section on removedOnCompletion:

    Sometimes you see people recommend setting removedOnCompletion to NO and fillMode to kCAFillModeBoth. This is not a good solution. It essentially makes the animation go on forever, which means the model layer is never updated. If you ask for the property’s value, you continue to see the model value, not what you see on the screen. If you try to implicitly animate the property afterward, it won’t work correctly because the CAAnimation is still running. If you ever remove the animation by replacing it with another with the same name, calling removeAnimationForKey: or removeAllAnimations, the old value snaps back. On top of all of that, it wastes memory.

    0 讨论(0)
  • 2021-01-15 11:06

    Set each animation’s removedOnCompletion to NO and its fillMode to kCAFillModeForwards.

    0 讨论(0)
提交回复
热议问题