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