****动画组
// 核心动画都是假象,不能改变layer的真实属性的值
// 展示的位置和实际的位置不同。实际位置永远在最开始位置
#import "HMViewController.h" @interface HMViewController () @property (weak, nonatomic) IBOutlet UIView *redView; @end @implementation HMViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CABasicAnimation *rotation = [CABasicAnimation animation]; rotation.keyPath = @"transform.rotation"; rotation.toValue = @M_PI_2; CABasicAnimation *position = [CABasicAnimation animation]; position.keyPath = @"position"; position.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 250)]; CABasicAnimation *scale = [CABasicAnimation animation]; scale.keyPath = @"transform.scale"; scale.toValue = @0.5; CAAnimationGroup *group = [CAAnimationGroup animation]; group.animations = @[rotation,position,scale]; group.duration = 2; // 取消反弹 group.removedOnCompletion = NO; group.fillMode = kCAFillModeForwards; [_redView.layer addAnimation:group forKey:nil]; } @end
时间: 2024-10-17 14:53:31