0
我得为我的视图中创建一个面具布局UIView的遮罩层,但我不能让我想获得创建使用CAShapeLayer()
@IBOutlet weak var viewToCrop: UIView!
let angle = CGFloat(2*M_PI/3)
func createMask() {
let mask = CAShapeLayer()
mask.frame = viewToCrop.layer.bounds
let heightButton = viewToCrop.frame.height
let lineWidth = -heightButton/tan(angle)
let width = viewToCrop.layer.frame.size.width
let height = viewToCrop.layer.frame.size.height
let path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, 0, 0)
CGPathAddLineToPoint(path, nil, width, 0)
CGPathMoveToPoint(path, nil, width - lineWidth, height)
CGPathAddLineToPoint(path, nil, lineWidth, height)
CGPathAddLineToPoint(path, nil, 0, 0)
mask.path = path
viewToCrop.layer.mask = mask
}
我需要建立这样的数字结果:
但是运行代码后,我得到的矩形。 我在做什么错?
P.S.我工作的一个传统项目上斯威夫特2
什么价值角度在这里? – agibson007
60度@ agibson007 –
也是为什么斯威夫特2? – agibson007