UIView和CAKeyframeAnimation缩放动画

UIView的缩放动画

 [UIView animateWithDuration:0.1 animations:^{
        self.transform = CGAffineTransformMakeScale(1.5, 1.5);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.1 animations:^{
            self.transform = CGAffineTransformMakeScale(0.9, 0.9);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.12 animations:^{
                self.transform = CGAffineTransformMakeScale(1.1, 1.1);
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:0.12 animations:^{
                    self.transform = CGAffineTransformMakeScale(1.0, 1.0);
                }];
            }];
        }];
    }];

CAKeyframeAnimation的缩放动画

UIView * view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
   view.backgroundColor = UIColor.blueColor;
   [self.view addSubview:view];
   
//    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];//整体变化
   CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.x"];//宽变化
//    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.y"];//高变化
   animation.duration  = 0.6;// 动画时间
   NSMutableArray *values = [NSMutableArray array];
   // 前两个是控制view的大小的;[缩小效果]
//    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
//    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1.0)]];
//    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
   
   // 前两个是控制view的大小的;[放大效果]
   [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
   [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.3, 1.3, 1.0)]];
   [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
   
   animation.values = values;
   animation.repeatCount = HUGE;//重复
   [view.layer addAnimation:animation forKey:nil];

你可能感兴趣的:(UIView和CAKeyframeAnimation缩放动画)