ios - CAShapeLayer 不能使用矩形路径?
问题描述
我画了一个虚线边框
let centerView = UIView()
centerView.frame = CGRect(x: 100, y: 100, width: 80, height: 50)
let shapeLayer = CAShapeLayer()
shapeLayer.fillColor = nil
shapeLayer.strokeColor = UIColor.gray.cgColor
shapeLayer.lineDashPattern = [3, 2]
shapeLayer.lineWidth = 0.5
shapeLayer.path = UIBezierPath(
roundedRect: centerView.bounds,
cornerRadius: 22
).cgPath
view.addSubview(centerView)
centerView.layer.addSublayer(shapeLayer)
当我点击Debug View Hierarchy
运行时问题:
A
CAShapeLayer
与矩形、圆角矩形或椭圆形路径一起使用。相反,使用经过适当转换的普通 CALayer 和cornerRadius
set。
如何解决?
解决方案
使用图层的 shadowPath 而不是这样的路径:
shapeLayer.shadowPath = UIBezierPath(
roundedRect: centerView.bounds,
cornerRadius: 22
).cgPath
推荐阅读
- go - 测试 row.scan 时如何模拟 sqlmock 错误
- java - Java继承转换运行时错误与编译器错误
- javascript - ParticleJS 与液体
- angular - 当验证中使用的 @Input 修饰变量发生更改时,为什么 *ngIf 不更新?
- java - 线程的意外行为
- flutter - 通过 dart 上的循环生成列表
- c - 为什么将“超出范围的整数转换为整数”会导致 IB,但将“超出范围的浮点数转换为整数”会导致 UB?
- mysql - 如何获取存储在 AWS 中的数据库的表关系(主键和外键)?
- java - Intellij IDEA:如果将依赖项存储格式更改为“Eclipse”,则“无法找到或加载主类”
- c - C. 错误:重复的函数定义。这可能是什么原因?