当先锋百科网

首页 1 2 3 4 5 6 7

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

1.简单的缩放代码

- (CAAnimation *)SetupScaleAnimation{
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.duration = ;
    scaleAnimation.fromValue = [NSNumber numberWithFloat:];
    scaleAnimation.toValue = [NSNumber numberWithFloat:];
    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, -)];
    moveAnimation.autoreverses = YES;
    moveAnimation.duration = ;
    return moveAnimation;
}

3.简单的旋转代码

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

4.动画组代码

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

调用代码

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

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

效果图

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