我以这种方式向我的UIView添加了底部圆角:
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.BottomLeft, .BottomRight], cornerRadii: CGSizeMake(20, 20)).CGPath
self.layer.mask = maskLayer
有两个问题。底部的第一张图片消失,其次是touchesBegan
,touchesMoved
等未被调用。
图片有3个约束:
答案 0 :(得分:0)
另一种圆角化方法(从未导致这些问题)是将这两种方法应用于您的视图:
myView.clipsToBounds = true
myView.layer.cornerRadius = 5 (play with this to get what you want!)
答案 1 :(得分:0)
将您的代码放在override
layoutSubviews
中,以便它使用更新的边界:
override func layoutSubviews() {
super.layoutSubviews()
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.BottomLeft, .BottomRight], cornerRadii: CGSizeMake(20, 20)).CGPath
self.layer.mask = maskLayer
}