CAAnimation

来源:互联网 发布:pc网络格斗游戏排行榜 编辑:程序博客网 时间:2024/06/04 20:11




//UIView 分为属性动画 和 过度动画
//Ios4.0之前要给视图添加动画:
//1.调用BeginAdimations 开始动画
//2.调用setAnimation  对动画进行配置
//3.设置动画内容
//4.调用comimitAnimations 结束动画

//    过度动画 需要一个容器  用这个容器做动画  在动画过程中让原先的View移除  再添加一个新的View
//    Begin an animation block.
//    Set the transition on the container view.
//    Remove the subview from the container view.
//    Add the new subview to the container view.


CAVasicAnimation:

// CABasic只是一个效果 不会改变属性值    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"bounds"];    animation.fromValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 0, 0)];    animation.toValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 320, 200)];    view2.layer.cornerRadius=100;    view2.clipsToBounds=YES;    animation.duration=10;    [view2.layer addAnimation:animation forKey:@"bounds"];



用CAKeyframeAnimation 实现视图晃动动画:

    CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"position"];    CGPoint postion = view1.layer.position;    keyFrame.values = @[                        [NSValue valueWithCGPoint:CGPointMake(postion.x, postion.y)],                        [NSValue valueWithCGPoint:CGPointMake(postion.x, postion.y)],                        [NSValue valueWithCGPoint:CGPointMake(postion.x-5, postion.y)],                        [NSValue valueWithCGPoint:CGPointMake(postion.x+5, postion.y)],                        [NSValue valueWithCGPoint:CGPointMake(postion.x, postion.y)],                        [NSValue valueWithCGPoint:CGPointMake(postion.x-5, postion.y)],                        [NSValue valueWithCGPoint:CGPointMake(postion.x, postion.y)],                        [NSValue valueWithCGPoint:CGPointMake(postion.x+5, postion.y)]                        ];    //淡入淡出效果    keyFrame.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];    //动画持续时间    keyFrame.duration = 0.5;    //图层加入动画    [view1.layer addAnimation:keyFrame forKey:@"keyFrame"];



用CATransition 实现翻转效果:

    CATransition *animation=[CATransition animation];    animation.type=@"cube";    animation.subtype=kCATransitionFromLeft;    animation.duration=1;    [view2.layer addAnimation:animation forKey:@"aa"];


当用多种动画时,可以放到CAAnimationGroup中,让CAAnimationGroup给你管理.






0 0
原创粉丝点击