您的位置:首页 > 其它

CoreAnimation

2016-05-17 13:13 351 查看
本文转自 http://www.jianshu.com/p/ee2d3a8b2d67
CoreAnimation 是直接作用在CALayer上的非常强大的跨Mac OS X 和 iOS平台的动画处理API。

CoreAnaimation的动画执行过程都是在后头执行的,不会阻塞主线程。



CABasicAnimation - 基本动画

// 动画:渐变

CABasicAnimation *fadeOutAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];

[fadeOutAnimation setFromValue:@1.0];

[fadeOutAnimation setToValue:[NSNumbernumberWithFloat:0.0]];

fadeOutAnimation.fillMode =kCAFillModeForwards;

//这个属性默认为 YES,那意味着,在指定的时间段完成后,动画就自动的从层上移除了。这个一般不用。

fadeOutAnimation.removedOnCompletion =NO;

/*

animationWithKeyPath的值:

transform.scale = 比例轉換

transform.scale.x = 闊的比例轉換

transform.scale.y = 高的比例轉換

transform.rotation.z = 平面圖的旋轉

opacity = 透明度

margin

zPosition

strokeEnd 慢慢出现

backgroundColor 背景颜色

cornerRadius 圆角

borderWidth

bounds

contents

contentsRect

cornerRadius

frame

hidden

mask

masksToBounds

opacity

position

shadowColor

shadowOffset

shadowOpacity

shadowRadius

*/


CAKeyframeAnimation——关键帧动画

// 动画:位置

//关键帧动画

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];

pathAnimation.calculationMode =kCAAnimationPaced;

pathAnimation.fillMode =kCAFillModeForwards;

pathAnimation.removedOnCompletion =NO;

CGMutablePathRef curvedPath =CGPathCreateMutable();

//绘制路径的起点。

CGPathMoveToPoint(curvedPath,NULL, viewOrigin.x, viewOrigin.y);

CGFloat btnPoint_y =_likeBtn.frame.origin.y;

//增加三个水平方向的拐点

CGPathAddLineToPoint(curvedPath,NULL, [selfrandomX], btnPoint_y - 150.f);

CGPathAddLineToPoint(curvedPath,NULL, [selfrandomX], btnPoint_y +100.f);

CGPathAddLineToPoint(curvedPath,NULL, [selfrandomX], btnPoint_y -300.f);

pathAnimation.path = curvedPath;

CGPathRelease(curvedPath);


CAAnimationGroup——动画组

CAAnimationGroup *group = [CAAnimationGroupanimation];

group.fillMode =kCAFillModeForwards;

group.removedOnCompletion =NO;

[group setAnimations:@[fadeOutAnimation, pathAnimation]];

// [group setAnimations:@[fadeOutAnimation]];

group.duration =4.f;

group.delegate =self;

[group setValue:animationViewforKey:@"imageViewBeingAnimated"];

[animationView.layeraddAnimation:groupforKey:@"groupAnimation"];

- (void)animationDidStart:(CAAnimation *)anim{

}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{

//动画结束后,将view从界面中清除

[[anim valueForKey:@"imageViewBeingAnimated"]removeFromSuperview];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: