2016-06-27 11 views
0

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: enter image description here
Bild nach der Animation: enter image description here

Antwort

2

Versuche let circleMaskPathInitial = UIBezierPath(ovalInRect: view.frame) zu let circleMaskPathInitial = UIBezierPath(ovalInRect: view.bounds) ändern. Meine Vermutung ist, dass Sie den Ursprung des Rechtecks ​​wirklich bei (0, 0) der Bildansicht haben wollen, aber der Ursprung des Bildes ist nicht (0, 0).

+0

musste auch circleMaskPathFinal mit Grenzen aktualisieren -> UIBezierPath (ovalInRect: CGRectInset (view.bounds, 10, 10)) –

+0

danke keith –