2016-07-16 95 views
0

下面的代碼生成以下效果:UIBezierPath - 斯威夫特2

let path = UIBezierPath() 
    path.moveToPoint(CGPoint(x: 0, y: 0)) 
    path.addLineToPoint(CGPoint(x: headerRect.width, y: 0)) 
    path.addLineToPoint(CGPoint(x: headerRect.width, y: headerRect.height)) 
    path.addLineToPoint(CGPoint(x: 0, y: headerRect.height-headerCutAway)) 
    headerMaskLayer?.path = path.CGPath 

Effect on Image

我想改變它,這樣的三角形是在右邊,而左邊,我該怎麼辦那?

回答

0

只是交換了y值在過去的兩個座標:

path.moveToPoint(CGPoint(x: 0, y: 0)) 
path.addLineToPoint(CGPoint(x: headerRect.width, y: 0)) 
path.addLineToPoint(CGPoint(x: headerRect.width, y: headerRect.height-headerCutAway)) 
path.addLineToPoint(CGPoint(x: 0, y: headerRect.height)) 
headerMaskLayer?.path = path.CGPath 
+0

它完美!非常感謝你,@Rob! – aghanim