底角不是快速工作

时间:2017-04-12 06:53:57

标签: ios swift uibezierpath

我尝试设置topright& bottomRight corner如下,但它无法正常工作

尝试1

let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: self.main_scroll.bounds,
                                    byRoundingCorners: [.TopRight, .BottomRight],
                                    cornerRadii: CGSize(width: 10.0, height: 10.0)).CGPath
self.main_scroll.layer.mask = maskLayer

尝试2

let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: self.main_scroll.frame, byRoundingCorners: UIRectCorner.BottomRight.union(.TopRight), cornerRadii: CGSizeMake(100, 100)).CGPath
self.main_scroll.layer.mask = maskLayer

尝试3

let rectShape = CAShapeLayer()
rectShape.bounds = self.main_scroll.frame
rectShape.position = self.main_scroll.center
rectShape.path = UIBezierPath(roundedRect: self.main_scroll.bounds, byRoundingCorners: [.BottomRight,.TopRight], cornerRadii: CGSize(width: 500, height: 500)).CGPath
self.main_scroll.layer.mask = rectShape

谢谢,

1 个答案:

答案 0 :(得分:2)

尝试使用DispatchQueue.main.async这对我有用

     DispatchQueue.main.async {
        let path = UIBezierPath(roundedRect: self.messageLabel.bounds,
                                byRoundingCorners:[.bottomRight, .topRight, .topLeft],
                                cornerRadii: CGSize(width: 8, height:  8))
        let maskLayer = CAShapeLayer()
        maskLayer.path = path.cgPath
        self.messageLabel.layer.mask = maskLayer
    }