iOS - CABasicAnimation

代码实例:

【1】

- (void)pulseClick
{   //!> 宽和高等比例转换
    CABasicAnimation * pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulse.duration = 0.1;  //!> 动画持续时间
    pulse.repeatCount = ; //!> 动画重复次数
    pulse.autoreverses = YES;//!> 动画执行完毕是否自动还原(YES就是自动还原到比例为1的状态)

    pulse.fromValue = [NSNumber numberWithFloat:];  //!> 动画执行开始的比例
    pulse.toValue = [NSNumber numberWithFloat:0.5];  //!> 动画执行终点的比例
    [_button.layer addAnimation:pulse forKey:nil];
}

【2】

- (void)pulseClick
{
    CABasicAnimation * pulse = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
    pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulse.duration = ;
    pulse.repeatCount = ;
    pulse.autoreverses = YES;

    pulse.fromValue = [NSNumber numberWithFloat:];
    pulse.toValue = [NSNumber numberWithFloat:];
    [_button.layer addAnimation:pulse forKey:nil];
}

【3】

- (void)pulseClick
{
    CABasicAnimation * pulse = [CABasicAnimation animationWithKeyPath:@"contents"];
    pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulse.duration = ;
    pulse.repeatCount = ;
    pulse.autoreverses = YES;
    //!> Contents是CALayer的属性,一般就是用作CGImageRef,常见用法就是下面这种用法;
    pulse.fromValue = (id)[UIImage imageNamed:@"flower"].CGImage;
    pulse.toValue = (id)[UIImage imageNamed:@"leaf"].CGImage;
    [_button.layer addAnimation:pulse forKey:nil];
}

【4】

- (void)pulseClick
{   //!> 一闪一闪的动画效果
    CABasicAnimation * pulse = [CABasicAnimation animationWithKeyPath:@"opacity"];
    pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulse.duration     = 0.3;
    pulse.repeatCount  = MAXFLOAT;
    pulse.fillMode     = kCAFillModeForwards;
    pulse.autoreverses = YES;

    pulse.fromValue = [NSNumber numberWithFloat:1.0];
    pulse.toValue   = [NSNumber numberWithFloat:0.2];

    [_button.layer addAnimation:pulse forKey:nil];
}

相信iOS客户端开发工程师都对CABasicAnimation都很了解。所以再补充记录一些笔记,关于animationWithKeyPath:

transform.scale = 比例转换

transfrom.scale.x = 宽的比例转换

transfrom.scale.y = 高的比例转换

transfrom.scale.z = 平面圆的旋转(三维z轴)

shadowColor =

shadowOpacity =

shadowRadius =

frame =

bounds =

hidder =

mask =

masksToBounds =

position =

opacity = 透明度

margin =

zPosition =

cornerRadius = 圆角

backgroundColor = 背景颜色

borderWidth = 边框

contents =

contentsRect =

上一篇:安装apk程序进android


下一篇:分布式搜索Elasticsearch——QueryBuilders.matchPhrasePrefixQuery