您可以这样做:
func curvedShapeFor(view: UIImageView, curvedPercent:CGFloat) ->UIBezierPath
{
let path = UIBezierPath()
path.move(to: CGPoint(x:0, y:0))
path.addLine(to: CGPoint(x:view.bounds.size.width, y:0))
path.addLine(to: CGPoint(x:view.bounds.size.width, y:view.bounds.size.height - (view.bounds.size.height*curvedPercent)))
path.addQuadCurve(to: CGPoint(x:0, y:view.bounds.size.height - (view.bounds.size.height*curvedPercent)), controlPoint: CGPoint(x:view.bounds.size.width/2, y:view.bounds.size.height))
path.addLine(to: CGPoint(x:0, y:0))
path.close()
return path
}
这样应用:
let shapeLayer = CAShapeLayer(layer: imageView.layer)
shapeLayer.path = self.curvedShapeFor(view: imageView,curvedPercent: 0.6).cgPath
shapeLayer.frame = imageView.bounds
shapeLayer.masksToBounds = true
imageView.layer.mask = shapeLayer