iOS开发之简单动画学习一

动画效果设计一直是iOS平台的优势,良好的动效设计可以很好地提升用户体验,丰富app的展示,而动画则是动效的基础支撑。今天就来看一下简单的动画学习。
概念性的东西我就不做介绍了,我就直接上代码(简单暴力,呵呵)

1.简单的缩放代码

- (CAAnimation *)SetupScaleAnimation{
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.duration = 3.0;
    scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
    scaleAnimation.toValue = [NSNumber numberWithFloat:3.0];
    scaleAnimation.repeatCount = MAXFLOAT;
    scaleAnimation.autoreverses = YES;
    scaleAnimation.fillMode = kCAFillModeForwards;
    scaleAnimation.removedOnCompletion = NO;
    
    return scaleAnimation;
}

2.简单的移动代码

- (CAAnimation *)SetupMoveAnimation{
    CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    moveAnimation.fromValue = [NSValue valueWithCGPoint:_label.layer.position];
    moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(_label.layer.position.x, 667-60)];
    moveAnimation.autoreverses = YES;
    moveAnimation.duration = 3.0;
    return moveAnimation;
}

3.简单的旋转代码

- (CAAnimation *)SetupRotationAnimation{
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
    rotationAnimation.duration = 1.5;
    rotationAnimation.autoreverses = YES;
    rotationAnimation.repeatCount = MAXFLOAT;
    rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    rotationAnimation.toValue = [NSNumber numberWithFloat:2 * M_PI];
    rotationAnimation.fillMode = kCAFillModeBoth;
    return rotationAnimation;
}

4.动画组代码

- (CAAnimation *)SetupGroupAnimation{
    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
    groupAnimation.duration = 3.0;
    groupAnimation.animations = @[[self SetupScaleAnimation], [self SetupMoveAnimation], [self SetupRotationAnimation]];
    groupAnimation.autoreverses = YES;
    groupAnimation.repeatCount = MAXFLOAT;
    return groupAnimation;
}

调用代码

- (void)SetupLayer{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(150, 20, 100, 30)];
    label.text = @"哈哈哈";
    label.font = [UIFont boldSystemFontOfSize:12];
    label.textColor = [UIColor redColor];
    [self.view addSubview:label];
    _label = label;
    [_label.layer addAnimation:[self SetupScaleAnimation] forKey:@"scale"];
}

虽然这些很初级,但是我之前一直不会怎么写,都是网上搜代码,所以我想学习一下,学习嘛,慢慢来,急也急不来,想做出很炫的动画,是要日积月累的。插入一我的故事:之前为了5.20,作为一个码农的我,算是费尽心思的取悦女朋友。学习的坚持是需要动力的,取悦我心爱之人是我的动力之一,其次还有就是我想做出更好的app,熟悉更多的知识。我想做出一个漂亮的动效给她看,就以葫芦画瓢仿照着写,终于有点成效,这就是我们码农的浪漫-用代码成就浪漫,更胜一切浪漫。
demo的下载地址
该demo只是为了实现动画效果,代码没做封装,望谅解,效果图如下:

用代码成就浪漫2.gif

学习笔记将持续更新。。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,142评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,223评论 4 61
  • 亲爱的自己,你好。现在的你已经20岁了,是一个即将步入社会的大三学生了。我不知道在未来的日子里你要经历什么。不...
    梦戏笔谈阅读 202评论 0 0
  • 这么几天过去了,我一直在思考我现在过的是什么日子和我想过什么日子。想明白了,心里总算透彻了不少,可还是有一点压抑。...
    高松火锅皮阅读 273评论 0 0
  • 浪淘沙双调小令 折柳赠故人,且听风吟 离人依依劝欢欣 也曾踱步芳丛,忆昔愿今 更惜别离时,对酒谈心 风也微寒酒亦沁...
    零壹Zerone_阅读 436评论 0 1