12
我一直在做一個簡單的UIBezierPath
動畫與斯威夫特UIBezierPath中風動畫。該路徑包括創建帶有彩色邊框的圓角矩形。動畫必須是彩色邊框的圖形。要做到這一點,我創建了UIBezierPath(roundedRect:, cornerRadius:)
斯威夫特:從中心
let layer = CAShapeLayer()
var viewPrueba = UIView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
viewPrueba = UIView(frame: CGRectMake(self.view.frame.width/2-100, self.view.frame.height/2 - 100, 200, 200))
self.view.addSubview(viewPrueba)
let path = UIBezierPath(roundedRect: CGRectMake(0, 0, 200, 200), cornerRadius: 40.0)
layer.path = path.CGPath
layer.fillColor = UIColor.clearColor().CGColor
layer.strokeColor = UIColor.blueColor().CGColor
layer.strokeStart = 0.0
layer.strokeEnd = 0.0
layer.lineWidth = 4.0
layer.lineJoin = kCALineJoinRound
viewPrueba.layer.addSublayer(layer)
let tapGR = UITapGestureRecognizer(target: self, action: #selector(ViewController.anim))
self.view.addGestureRecognizer(tapGR)
}
func anim() {
let anim1 = CABasicAnimation(keyPath: "strokeEnd")
anim1.fromValue = 0.0
anim1.toValue = 1.0
anim1.duration = 4.0
anim1.repeatCount = 0
anim1.autoreverses = false
anim1.removedOnCompletion = false
anim1.additive = true
anim1.fillMode = kCAFillModeForwards
self.layer.addAnimation(anim1, forKey: "strokeEnd")
}`
它運作良好,一個CAShapeLayer
。唯一的問題是,動畫從頂部中心廣場的左上部分,而不是開始。我怎樣才能做到這一點?
我在爲了實現這一發現的唯一的事情就是用一個圓圈,而不是一個矩形,這不是我們想要做的事情吧。
由於
作品般的魅力!謝謝! :) – rulilg