0
我有一個目標圖像,我試圖使用動畫來裁剪外環而不調整其大小。我正在使用UIBelzierPath來做到這一點,我有一些原因不能將它直接放在我的圖像上,因爲它只是動畫像右下角那樣,直接應用於imageView。我究竟做錯了什麼?我與動畫鬥爭,所以任何幫助都會很棒。不以imageView爲中心的動畫
@IBOutlet weak var image: UIImageView!
@IBAction func animate(sender: AnyObject) {
animateCollapse()
}
private func animateCollapse() {
let view = image
let circleMaskPathInitial = UIBezierPath(ovalInRect: view.frame)
let circleMaskPathFinal = UIBezierPath(ovalInRect: CGRectInset(view.frame, 10 , 10))
performAnimation(circleMaskPathInitial, finalPath: circleMaskPathFinal)
}
private func performAnimation(initialPath: UIBezierPath, finalPath: UIBezierPath) {
let maskLayer = CAShapeLayer()
maskLayer.path = finalPath.CGPath
image.layer.mask = maskLayer
let maskLayerAnimation = CABasicAnimation(keyPath: "path")
maskLayerAnimation.fromValue = initialPath.CGPath
maskLayerAnimation.toValue = finalPath.CGPath
maskLayerAnimation.duration = 1.0
maskLayerAnimation.delegate = self
maskLayer.addAnimation(maskLayerAnimation, forKey: "path")
}
也必須更新circleMaskPathFinal帶邊界 - > UIBezierPath(ovalInRect:CGRectInset(view.bounds,10,10)) –
謝謝基思 –