Ich habe ein Maskenlayout für meine Ansicht zu erstellen, aber ich kann nicht das Ergebnis, das ich bekommenfür UIView mit 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
}
Ich muss erhalten solche Figur erstellen:
jedoch nach mir Code ausgeführt erhalte ich die rechteckig. Was mache ich falsch?
P.S. Ich arbeite an einem älteren Projekt auf Swift 2
Welchen Wert Winkel hier ist? – agibson007
60 Grad @ agibson007 –
auch warum Swift 2? – agibson007