@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// 创建动画
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"transform.scale";
anim.toValue = @(1.5);
anim.repeatCount = CGFLOAT_MAX;
anim.duration = 0.5;
// 动画完成后不删除动画
anim.removedOnCompletion = NO;
anim.autoreverses = YES;
// 添加动画
[self.redView.layer addAnimation:anim forKey:@"transform.scale"];
}
@end