swift 绘制、动画基础 (CAShapeLayer、CABasicAnimation)
来源:互联网 发布:知乎怎么关注话题 编辑:程序博客网 时间:2024/06/09 19:02
//MARK: 绘制虚线 let layer0 = CAShapeLayer() layer0.strokeColor = UIColor.green.cgColor layer0.lineWidth = 0.5 //线段宽度10 间距10 let arr :NSArray = NSArray(array: [10,10]) //基于线段的起始位置 layer0.lineDashPhase = 0 layer0.lineDashPattern = arr as? [NSNumber] self.view.layer.addSublayer(layer0) //路径 let mdotteShapePath = CGMutablePath() mdotteShapePath.move(to: CGPoint(x:0, y: 30)) mdotteShapePath.addLine(to: CGPoint(x:UIScreen.main.bounds.size.width, y:30)) layer0.path = mdotteShapePath //MARK: 实心矩形 let layer = CAShapeLayer() layer.frame = CGRect(x:80, y:50, width:150, height:50) layer.backgroundColor = UIColor.green.cgColor view.layer.addSublayer(layer) //MARK: 矩形框 let layer1 = CAShapeLayer() layer1.fillColor = UIColor.clear.cgColor layer1.strokeColor = UIColor.green.cgColor view.layer.addSublayer(layer1) let path1 = UIBezierPath(rect: CGRect(x:80, y:110, width:150, height:50)) layer1.path = path1.cgPath //MARK: 圆角矩形 let path2 = UIBezierPath(roundedRect: CGRect(x:80, y:170, width:150, height:50), cornerRadius: 50) let layer2 = CAShapeLayer() layer2.path = path2.cgPath layer2.fillColor = UIColor.clear.cgColor layer2.strokeColor = UIColor.green.cgColor view.layer.addSublayer(layer2) //MARK: 圆形 let radius: CGFloat = 20 let startAngle: CGFloat = 0.0 let endAngle: CGFloat = CGFloat(M_PI * 2) let path3 = UIBezierPath(arcCenter: view.center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true) let layer3 = CAShapeLayer() layer3.path = path3.cgPath layer3.fillColor = UIColor.clear.cgColor layer3.strokeColor = UIColor.green.cgColor view.layer.addSublayer(layer3) //MARK: 贝塞尔曲线 let startPoint = CGPoint(x:20, y:400) let endPoint = CGPoint(x:320, y:400) let controlPoint = CGPoint(x:170, y:300) let controlPoint1 = CGPoint(x:120, y:300) let controlPoint2 = CGPoint(x:220, y:500) //曲线1 let path10 = UIBezierPath() let layer10 = CAShapeLayer() path10.move(to: startPoint) path10.addQuadCurve(to: endPoint, controlPoint: controlPoint) layer10.path = path10.cgPath layer10.fillColor = UIColor.clear.cgColor layer10.strokeColor = UIColor.black.cgColor view.layer.addSublayer(layer10) //曲线2 let path20 = UIBezierPath() let layer20 = CAShapeLayer() path20.move(to: startPoint) path20.addCurve(to: endPoint, controlPoint1: controlPoint1, controlPoint2: controlPoint2) layer20.path = path20.cgPath layer20.fillColor = UIColor.clear.cgColor layer20.strokeColor = UIColor.black.cgColor view.layer.addSublayer(layer20) //MARK: 动画 //动画1 let animation = CABasicAnimation(keyPath: "strokeEnd") animation.fromValue = 0 animation.toValue = 1 animation.duration = 2 layer10.add(animation, forKey: "") //动画2 layer20.strokeStart = 0 layer20.strokeEnd = 1 let animation21 = CABasicAnimation(keyPath: "strokeStart") //起始位置中间 结束为止左端 animation21.fromValue = 0.5 animation21.toValue = 0 animation21.duration = 2 let animation22 = CABasicAnimation(keyPath: "strokeEnd") //起始位置中间 结束为止右端 animation22.fromValue = 0.5 animation22.toValue = 1 animation22.duration = 2 layer20.add(animation21, forKey: "") layer20.add(animation22, forKey: "") //动画3 let animation23 = CABasicAnimation(keyPath: "lineWidth") animation23.fromValue = 1 animation23.toValue = 10 animation23.duration = 5 layer1.add(animation23, forKey: "")
0 0
- swift 绘制、动画基础 (CAShapeLayer、CABasicAnimation)
- 贝塞尔结合CAShapeLayer绘制路线,CABasicAnimation实现的小动画
- iOS动画详解 (CABasicAnimation,UIBezierPath,CAShapeLayer)
- Swift CAShapeLayer,UIBezierPath绘制图形
- iOS 使用UIBezierPath, CAShapeLayer, CABasicAnimation动态绘制折线
- 仿支付宝的付款转圈动画---CAShapeLayer、UIBezierPath、CABasicAnimation
- iOS CoreAnimation 基础动画CABasicAnimation
- IOS_ UIBezierPath + CABasicAnimation + CAShapeLayer
- UIBezierPath和CAShapeLayer结合绘制任意弧度的圆形(包含旋转动画)
- CABasicAnimation(基础属性动画)的简单使用
- 猫猫学IOS(三十九)UI之核心动画之CABasicAnimation(基础动画)
- AJ学IOS(39)UI之核心动画之CABasicAnimation(基础动画)
- 核心动画基础动画(CABasicAnimation)关键帧动画
- iOS编程——Swift实现多段CAShapeLayer动画
- CABasicAnimation 动画
- CABasicAnimation 动画
- CABasicAnimation 动画
- CABasicAnimation 动画
- 前端模块化之路
- Lnmp下 php安全策略
- sql学习笔记
- 关于b-jui框架,datagrid传参数的问题
- ovs总结与常用命令及流表介绍
- swift 绘制、动画基础 (CAShapeLayer、CABasicAnimation)
- mybatis开启数据库字段自动映射为java驼峰命名规则
- 多渠道整合—在线客服系统发展新路径
- 添加远程仓库,并建立本地branch
- 结构体和联合体
- Leetcode-263 Ugly Number
- 416. Partition Equal Subset Sum
- TCP连接过程
- 单例模式