用layer添加UIView的动画

项目有时会遇到用UIView 添加动画的情况,这里我觉得在layer上添加动画比较好,因为可以详细地设定动画属性,方便理解

下面是一个旋转动画:

-(void)roundBtnAction:(id)sender {
    
    
    UIButton * button = (UIButton *)sender;
    
    //Animation自旋转(layer动画):
    CABasicAnimation* rotationAnimation;
    
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 1 ];
    
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    rotationAnimation.duration = 1;
    
    rotationAnimation.repeatCount = 0;//你可以设置到最大的整数值
    
    rotationAnimation.cumulative = NO;
    
    rotationAnimation.removedOnCompletion = NO;
    
    rotationAnimation.fillMode = kCAFillModeForwards;
    
    [button.layer addAnimation:rotationAnimation forKey: @"Rotation"];
   
}

原文:http://www.cnblogs.com/A--G/p/4679316.html

上一篇:Express4.x API (四):Router (译)


下一篇:windows下解决python输出utf-8中文