美文网首页
iOS-核心动画

iOS-核心动画

作者: SmileYang966 | 来源:发表于2020-05-14 18:54 被阅读0次
coreAnimation.png
  1. 基本动画CABasicAnimation,确定keyPath,animation的duration、fromValue以及toValue。
 // KeyPath确定为position.x,
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.x"];   
  //动画执行的duration
    animation.duration = 0.8f;
 //动画执行的fromValue到tovalue
    animation.fromValue = @(self.redView.center.x);
    animation.toValue = @(self.redView.center.x+50);
    
    //一个时间函数,表示它是以怎么样的时间运行
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    animation.repeatCount = HUGE_VALF;
    animation.repeatDuration = 2;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    
    [self.redView.layer addAnimation:animation forKey:nil];
  1. 关键帧动画,动画可以按照一个指定的path执行,或者按照一组特定的values去执行。
//关键帧动画
-(void)keyFrameAnimation{
//动画执行的路径
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:self.redView.center radius:100 startAngle:0 endAngle:M_PI*2 clockwise:YES];
    
    CAKeyframeAnimation *keyFrameAnmiation = [CAKeyframeAnimation animation];
    keyFrameAnmiation.path = path.CGPath;
    //动画执行的keyPath
    keyFrameAnmiation.keyPath = @"position";
    keyFrameAnmiation.duration = 5;
    keyFrameAnmiation.repeatCount = MAXFLOAT;
    [self.redView.layer addAnimation:keyFrameAnmiation forKey:nil];
}
  1. 动画组,
//动画组
-(void)animationGroup{
    //1.创建一个基础动画
    CABasicAnimation *basicAnimation = [CABasicAnimation animation];
    basicAnimation.keyPath = @"transform.scale";
    basicAnimation.fromValue = @1.0;
    basicAnimation.toValue = @0.2;
    
    //2.创建一个帧动画
    CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animation];
    keyFrameAnimation.keyPath = @"position";
    keyFrameAnimation.path = [UIBezierPath bezierPathWithArcCenter:self.redView.center radius:100 startAngle:0 endAngle:M_PI * 2 clockwise:YES].CGPath;

    //3.创建一个动画组
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.duration = 5.0f;
    group.autoreverses = YES;
    group.animations = @[basicAnimation,keyFrameAnimation];
    
    [self.redView.layer addAnimation:group forKey:nil];
}
  1. 转场动画


    May-14-2020 18-52-28.gif
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.imgView = [[UIImageView alloc]initWithFrame:CGRectMake(100,100,200, 200)];
    self.imgView.backgroundColor = UIColor.redColor;
    self.imgView.image = [UIImage imageNamed:@"1.jpg"];
    [self.view addSubview:self.imgView];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    static int index = 1;
    index++;
    NSString *imgName = [NSString stringWithFormat:@"%d.jpg",index];
    self.imgView.image = [UIImage imageNamed:imgName];
    if (index == 4) {
        index = 1;
    }
    
    CATransition *transition = [CATransition animation];
    transition.type = @"pageCurl";
    transition.subtype = kCATransitionFromLeft;
    transition.duration = 1.0f;
    [self.imgView.layer addAnimation:transition forKey:nil];
}

相关文章

  • 随手记

    核心动画翻译https://zsisme.gitbooks.io/ios-/content/chapter14/l...

  • 随手记

    核心动画翻译https://zsisme.gitbooks.io/ios-/content/chapter14/l...

  • 2019-07-15

    iOS高级核心动画技巧 浏览地址:https://zsisme.gitbooks.io/ios-/content/...

  • 感觉有用的文章留存

    0.ios核心动画高级技巧https://zsisme.gitbooks.io/ios-/content/inde...

  • iOS-核心动画

    前言:核心动画的基础知识,包括基本动画、帧动画、转场动画相关知识。 一、核心动画(Core Animation) ...

  • iOS-核心动画

    CAAnimation:核心动画 是所有动画的父类 1>.CAMediaTiming媒体时间类协议 2>.CAAn...

  • iOS-核心动画

    核心动画(Core Animation) 一、Core animation简单介绍 1.Core Animatio...

  • iOS-核心动画

    基本动画CABasicAnimation,确定keyPath,animation的duration、fromVal...

  • iOS-核心动画(UIView封装动画)(链接)

    文顶顶最怕你一生碌碌无为 还安慰自己平凡可贵 iOS动画(一):拍电影与CABasicAnimation iOS开...

  • iOS-核心动画高级技巧

    iOS核心动画高级技巧 gitbook上的地址 github上的地址

网友评论

      本文标题:iOS-核心动画

      本文链接:https://www.haomeiwen.com/subject/acfxohtx.html