iOS 动态画圆圈
2015-07-09 10:57
309 查看
-(void)setUpAnimationLayer
{
//因为会多次点击,所以要将该图层移除,并且指针置空
[self.animationLayer
removeFromSuperlayer];
self.animationLayer =
nil;
UIBezierPath * path = [UIBezierPath
bezierPath];
//参数依次是:圆心坐标,半径,开始弧度,结束弧度
画线方向:yes为顺时针,no为逆时针
[path addArcWithCenter:CGPointMake(50,
100)
radius:50
startAngle:0
endAngle:2*M_PI
clockwise:TRUE];
CAShapeLayer * pathLayer = [CAShapeLayer
layer];
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor
blueColor]CGColor];//画线颜色
pathLayer.fillColor = [[UIColor
redColor]CGColor];//填充颜色
pathLayer.lineJoin =
kCALineJoinRound;
pathLayer.lineWidth =
6.0f;
[self.view.layer
addSublayer:pathLayer];
[self
setAnimationLayer:pathLayer];//把pathLayer赋给属性animationLayer
}
- (IBAction)btnClick:(id)sender {
[self
setUpAnimationLayer];
[self.animationLayer
removeAllAnimations];//每次将之前的动画都清除了
// keyPath = strokeEnd
动画的fromValue = 0,toValue = 1
表示
这里我们分3个点说明动画的顺序 strokeEnd从结尾开始清除
首先整条路径先清除后2/3,接着清除1/3
效果就是正方向画出路径
CABasicAnimation *pathAnimation = [CABasicAnimation
animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration =
10.0;
pathAnimation.fromValue =
@(0);
pathAnimation.toValue =
@(1);
[self.animationLayer
addAnimation:pathAnimation
forKey:@"strokeEnd"];
}
{
//因为会多次点击,所以要将该图层移除,并且指针置空
[self.animationLayer
removeFromSuperlayer];
self.animationLayer =
nil;
UIBezierPath * path = [UIBezierPath
bezierPath];
//参数依次是:圆心坐标,半径,开始弧度,结束弧度
画线方向:yes为顺时针,no为逆时针
[path addArcWithCenter:CGPointMake(50,
100)
radius:50
startAngle:0
endAngle:2*M_PI
clockwise:TRUE];
CAShapeLayer * pathLayer = [CAShapeLayer
layer];
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor
blueColor]CGColor];//画线颜色
pathLayer.fillColor = [[UIColor
redColor]CGColor];//填充颜色
pathLayer.lineJoin =
kCALineJoinRound;
pathLayer.lineWidth =
6.0f;
[self.view.layer
addSublayer:pathLayer];
[self
setAnimationLayer:pathLayer];//把pathLayer赋给属性animationLayer
}
- (IBAction)btnClick:(id)sender {
[self
setUpAnimationLayer];
[self.animationLayer
removeAllAnimations];//每次将之前的动画都清除了
// keyPath = strokeEnd
动画的fromValue = 0,toValue = 1
表示
这里我们分3个点说明动画的顺序 strokeEnd从结尾开始清除
首先整条路径先清除后2/3,接着清除1/3
效果就是正方向画出路径
CABasicAnimation *pathAnimation = [CABasicAnimation
animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration =
10.0;
pathAnimation.fromValue =
@(0);
pathAnimation.toValue =
@(1);
[self.animationLayer
addAnimation:pathAnimation
forKey:@"strokeEnd"];
}
相关文章推荐
- iOS 开发中问题 ——tableView分行线距离左侧15像素空白的解决办法
- iOS GCD使用
- iOS开发——为什么我的scanForPeripheralsWithServices根本不起作用
- iOS中,在类的源文件(.m)中,@interface部分的作用?
- IOS/MAC环境下thrift的安装
- 用CocoaPods做iOS程序的依赖管理
- iOS 远程推送的详细配置
- 【转】iOS应用崩溃日志分析
- iOS7.1及以后版本企业应用发布过程中的问题及解决方案
- iOS中滤镜的使用(一) 马赛克滤镜
- cout的输出格式初探3
- IOS延长启动画面的两种方法
- cout的输出格式初探2
- 源码推荐(7.09):iOS简单即时通讯 自定义协议实现 了解传输基本原理,仿陌陌的可滑动Segment
- IOS 数据存储之 FMDB 详解
- iOS开发系列--通知与消息机制
- iOS开发多线程篇—GCD介绍
- Xcode5.1和IOS8.3真机调试
- ios NSClassFromString 返回空指针
- iOS 9可以猜测你想打开哪个应用