Ich habe ein Bild von einem Ziel, und ich versuche, Animation verwenden, um den äußeren Ring ohne Größe zu schneiden. Ich benutze UIBelzierPath, um dies zu tun, und ich bin aus irgendeinem Grund nicht in der Lage, dies direkt auf mein Bild zu zentrieren, da es nur die untere rechte Ecke animiert, wie es für das imageView direkt bedeutet. Was mache ich falsch? Ich kämpfe mit Animation, so dass jede Hilfe wunderbar wäre.Animation nicht zentriert auf imageView (iOS)
@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")
}
Bild:
Bild nach der Animation:
musste auch circleMaskPathFinal mit Grenzen aktualisieren -> UIBezierPath (ovalInRect: CGRectInset (view.bounds, 10, 10)) –
danke keith –