搜索
您的当前位置:首页正文

Core Animation iOS 核心动画

来源:二三娱乐
8D308416-EEFF-4B3B-8ABD-C0E65FB1EC5A.png

openGL 还有手机底层硬件的东西,除了面试的时候要问你,可能平时开发app 你基本用不到,用不到基本和不会没有什么差距,因为知道名字不代表什么。
关于Animation 架构

B5A050BE-C9E1-4D18-8CF5-C2B9DF3852D6.png

在文档辅路里面明显感觉到,平时用的比较的一定是CABasicAnimation

4、本质
动画的本质,在最上的层面上,我暂时理解为对于layer 变换,如果边框的约束,透明度,大小,位置,z轴的约束等。layer之间的切换。
底层的还没有研究,不过如果可以研究加利用这样才能真的了解和领悟。

5、总结
这里一行代码没有写,感觉无聊
code

  • (IBAction)baseAnimation:(id)sender {
    CABasicAnimation *fadAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadAnimation.fromValue = @(1.0);
    fadAnimation.toValue = @(0.0);
    fadAnimation.duration = 1;
    [self.imgView.layer addAnimation:fadAnimation forKey:@"opacity"];
    }

  • (IBAction)pathRefAnimation :(id)sender {
    CGMutablePathRef thePath = CGPathCreateMutable();
    CGPathMoveToPoint(thePath, nil, 74, 74);
    CGPathAddCurveToPoint(thePath, NULL, 74, 500, 320,500 , 320, 74);
    CGPathAddCurveToPoint(thePath, NULL, 320, 500, 566, 500, 566, 74);
    CAKeyframeAnimation *theAnimation;
    theAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];;
    theAnimation.path = thePath;
    theAnimation.duration = 5;
    [self.imgView.layer addAnimation:theAnimation forKey:@"position"];
    }

  • (IBAction)keyPathAnimations:(id)sender {
    CAKeyframeAnimation *widthAnimation = [CAKeyframeAnimation animationWithKeyPath:@"borderWidth"];
    NSArray *widthArray = [NSArray arrayWithObjects:@1.0,@10.0,@4.0,@30.0,@0.5,@15.0,@2.0,@50,@0.0, nil];
    widthAnimation.values = widthArray;
    widthAnimation.calculationMode = kCAAnimationPaced;

    CAKeyframeAnimation *colorAnimation = [CAKeyframeAnimation animationWithKeyPath:@"borderColor"];
    NSArray *colorValues = [NSArray arrayWithObjects:(id)[UIColor greenColor].CGColor,(id)[UIColor blackColor].CGColor,(id)[UIColor redColor].CGColor,nil];
    colorAnimation.values = colorValues;
    colorAnimation.calculationMode = kCAAnimationPaced;

    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = [NSArray arrayWithObjects:colorAnimation,widthAnimation, nil];
    group.duration = 5.0;
    [self.imgView.layer addAnimation:group forKey:@"bowc"];
    }

这是三个苹果文档动画,我简单的自己写了一边,改了几个参数。

这里要说明的时候苹果本身封装一些简单实用的基本动画,根据键值来设置,用最少的代码来实现动画,可能让你不懂,但是基本架构掌握了,其他的就是时间问题。目前我正在和好朋友设计app,感觉代码是个逻辑的表现形式,比如动画的快慢模拟,动效的拟物话,都不是我们这码农平时接触到的,多看看其他方面的东西,还是很用帮助的。


希望这一年有新的收获和领悟。

Top