我想缩小三角形,如下所示:
但三角形向上收缩如下:
转换代码如下:
layer.setAffineTransform(CGAffineTransformMakeScale(1.0, 0.5))
我尝试使用anchorPoint,但我无法成功。
//: Playground - noun: a place where people can play
import UIKit
let view = UIView(frame: CGRectMake(0, 0, 200, 150))
let layer = CAShapeLayer()
let triangle = UIBezierPath()
triangle.moveToPoint (CGPointMake( 50, 150))
triangle.addLineToPoint(CGPointMake(100, 50))
triangle.addLineToPoint(CGPointMake(150, 150))
triangle.closePath()
layer.path = triangle.CGPath
layer.strokeColor = UIColor.blueColor().CGColor
layer.lineWidth = 3.0
view.layer.addSublayer(layer)
view
layer.setAffineTransform(CGAffineTransformMakeScale(1.0, 0.5))
view
Anish给了我一个建议,但效果不好:
layer.setAffineTransform(CGAffineTransformMakeScale(2.0, 0.5))