如何快速添加弯曲的视图左上角

时间:2018-07-18 09:10:54

标签: swift uiviewanimation uibezierpath cgpoint

如何在曲线的左上角添加uiview。

我已经做了类似的事情

class curvedView: UIView {

    override func draw(_ rect: CGRect) {
        let color = UIColor.blue
        let y:CGFloat = 0
        let myBezier = UIBezierPath()
        myBezier.move(to: CGPoint(x: 0, y: y))
        myBezier.addQuadCurve(to: CGPoint(x: rect.width, y: y), controlPoint: CGPoint(x: rect.width / 2, y: rect.height * 2))
        myBezier.addLine(to: CGPoint(x: rect.width, y: rect.height))
        myBezier.addLine(to: CGPoint(x: 0, y: rect.height))
        myBezier.close()
        color.setFill()
        myBezier.fill()

    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.backgroundColor = UIColor.clear

    } 

}

但这会创建U形曲线,但我希望曲线从x位置180到Y位置250。

任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:0)

您可以尝试这些代码,它将为您提供帮助

let path = UIBezierPath(roundedRect:viewToRound.bounds, byRoundingCorners:[.TopRight, .BottomLeft], cornerRadii: CGSizeMake(20, 20))
let maskLayer = CAShapeLayer()

maskLayer.path = path.CGPath
viewToRound.layer.mask = maskLayer