一, 创建自定义视图
func createLayerWithView(view : UIView){
let viewWidth=CGRectGetWidth(view.frame);
let viewHeight=CGRectGetHeight(view.frame);
let point1 = CGPointMake(0,10);
let point2 = CGPointMake(viewWidth-35,10);
let point3 = CGPointMake(viewWidth-25, 0);
let point4 = CGPointMake(viewWidth-15,10);
let point5 = CGPointMake(viewWidth,10);
let point6 = CGPointMake(viewWidth , viewHeight);
let point7 = CGPointMake(0, viewHeight);
let bezierPath = UIBezierPath()
bezierPath.moveToPoint(point1)
bezierPath.addLineToPoint(point2)
bezierPath.addLineToPoint(point3)
bezierPath.addLineToPoint(point4)
bezierPath.addLineToPoint(point5)
bezierPath.addLineToPoint(point6)
bezierPath.addLineToPoint(point7)
bezierPath.closePath()
let layer = CAShapeLayer()
layer.path = bezierPath.CGPath
view.layer.mask = layer
}
二, 给它位置大小
var customView : UIView!
self.customView = UIView.init(frame: CGRectMake(WIDTH-(WIDTH/4+30),200, WIDTH/4+20,150))
customView.backgroundColor = UIColor.blackColor()
customView.alpha = 0.8
self.view.addSubview(customView)
self.createLayerWithView(self.customView)
三, 也可以在此设置动画
UIView.animateWithDuration(0.8, animations: {
})