IOS 添加收藏的动画效果

简介:
- (void)showAnimation {
  CGPoint lbCenter = self.headerImageView.center;
  
  //the image which will play the animation soon
  UIImageView *imageView = [[UIImageView alloc] initWithImage:self.headerImageView.image];
  imageView.contentMode = UIViewContentModeScaleToFill;
  imageView.frame = self.headerImageView.frame;
  imageView.hidden = YES;
  imageView.center = lbCenter;
  
  //the container of image view
  CALayer *layer = [[CALayer alloc]init];
  layer.contents = imageView.layer.contents;
  layer.frame = imageView.frame;
  layer.opacity = 1;
  layer.cornerRadius = self.headerImageView.corneradus;
  layer.masksToBounds = YES;
  [self.view.layer addSublayer:layer];
  
  //动画 终点 都以self.view为参考系
  CGPoint endpoint = [self.view convertPoint:_favImageView.center fromView:self.navView];
  UIBezierPath *path = [UIBezierPath bezierPath];
  //动画起点
  CGPoint startPoint = [self.view convertPoint:lbCenter fromView:self.headerImageView.superview];
  [path moveToPoint:startPoint];
  //贝塞尔曲线控制点
  float sx = startPoint.x;
  float sy = startPoint.y;
  float ex = endpoint.x;
  float ey = endpoint.y;
  float x = sx + (ex - sx) / 3;
  float y = sy + (ey - sy) * 0.5 - 110;
  CGPoint centerPoint=CGPointMake(x, y);
  [path addQuadCurveToPoint:endpoint controlPoint:centerPoint];
  
  //key frame animation to show the bezier path animation
  CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
  animation.path = path.CGPath;
  animation.removedOnCompletion = NO;
  animation.fillMode = kCAFillModeForwards;
  animation.duration = 1.0;
  animation.delegate = self;
  animation.autoreverses = NO;
  animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  [layer addAnimation:animation forKey:@"buy"];
  
  self.headerLayer = layer;
}

- (void)animationDidStart:(CAAnimation *)anim {
  if ([self.headerLayer animationForKey:@"buy"] == anim) {
    DDLogVerbose(@"animation start");
  }
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
  if (flag &&  [self.headerLayer animationForKey:@"buy"] == anim) {
     self.headerLayer.hidden = YES;
    [self.headerLayer removeAnimationForKey:@"buy"];
   
    [UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
      self.headerLayer.opacity = 0.0;
    } completion:^(BOOL finished) {
      if (finished) {
        [self.headerLayer removeFromSuperlayer];
        
        CGFloat duration = 0.4;
        [UIView animateWithDuration:duration animations:^{
          _favImageView.transform = CGAffineTransformMakeScale(1.55, 1.55);
        } completion:^(BOOL finished) {
          [UIView animateWithDuration:duration animations:^{
            _favImageView.transform = CGAffineTransformIdentity;
          }];
        }];
      }
    }];
  }
}

此文章不是给大家看的,看得懂的自然会明白怎么用!

目录
相关文章
|
存储 API iOS开发
iOS UIView动画效果
iOS UIView动画效果
|
iOS开发
iOS开发- 点击通知栏回到顶部的动画效果
iOS开发- 点击通知栏回到顶部的动画效果
110 0
iOS开发- 点击通知栏回到顶部的动画效果
iOS- 点赞动画效果
iOS- 点赞动画效果
118 0
|
iOS开发
IOS常用动画效果
IOS常用动画效果
115 0
|
存储 iOS开发
iOS的GIF动画效果实现
GIF图像格式是常见的一种动态图片格式,无论是在Web端还是在移动端都经常遇到,但是考虑目前iOS还无法原生展现GIF图片,而对于GIF的原生支持暂时也没有像JPG、PNG等图像格式支持得这么全面,因此本文从图片的合成与分解角度来为大家讲解GIF的知识,结合ImageIO框架可以更方便地实现GIF图片的合成与分解。
8862 0