CABasicAnimation-CoreAnimation

2018-05-29  本文已影响0人  M_PI_4

基础动画:

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    CABasicAnimation *anim = [CABasicAnimation animation];
    
    anim.keyPath = @"position";
   
    anim.toValue = [NSValue valueWithCGPoint:CGPointMake(0, 162)];
    anim.repeatCount = 2.0f;
    anim.duration  = 0.5f;
    
    // 动画先加速后减速
    anim.timingFunction =
    [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
    anim.autoreverses = YES;        //结束后执行逆动画
    [_imageV.layer addAnimation:anim forKey:@"do"];
}  


keyPath可以使用的key

transform.rotation.x 围绕x轴翻转
transform.rotation.y 围绕y轴翻转
transform.rotation.z 围绕z轴翻转
transform.rotation 默认围绕z轴

transform.scale.x x方向缩放
transform.scale.y y方向缩放
transform.scale.z z方向缩放
transform.scale 所有方向缩放

transform.translation.x x方向移动
transform.translation.y x方向移动
transform.translation.z x方向移动
transform.translation 移动

opacity 透明度
backgroundColor 背景颜色
cornerRadius 圆角
borderWidth 边框宽度
bounds 大小
contents 内容,用于图片等
contentsRect 可视内容 0~1

hidden 是否隐藏
position

shadowColor
shadowOffset
shadowOpacity
shadowRadius

上一篇 下一篇

猜你喜欢

热点阅读