2016-05-29 96 views
0

我以前有過這個問題,但不知道它是什麼。Animate UIView out scale的行爲奇怪

如果我在Playground中爲「獨立」動畫製作視圖,這種事情看起來很好,但現在看起來就像在提供的GIF中。

動畫效果看起來很好,但是當我想將它製作成動畫(縮放)時,它會變得最大化然後消失。

enter image description here

下面是它的動畫代碼:

self.circleView.transform = CGAffineTransformIdentity 
UIView.animateWithDuration(0.5, delay: 0, options: [], animations: { 
    self.circleView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001); 
}, completion: { 
    finished in 
    if finished { 
     self.resetStyle() 
     self.circleView.hidden = true 
     self.circleView.transform = CGAffineTransformIdentity 
    } 
}) 

func resetStyle() { 
    self.circleView.transform = CGAffineTransformIdentity 
    self.circleView.backgroundColor = nil 
    self.textLabel.textColor = UIColor.blackColor() 
} 
+1

什麼是'self.resetStyle()'做什麼? – Cjay

+0

我會將其添加到問題 – netigger

+0

您是否嘗試將此動畫應用於視圖的圖層,而不是直接將其應用於'UIView'?用3D轉換替換你的仿射變換? –

回答

0

試試這個:

@IBOutlet weak var circleView: UIView! 

@IBAction func leftAction(sender: AnyObject) { 
    self.circleView.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1) 
    UIView.animateWithDuration(0.5) { 
     self.circleView.layer.transform = CATransform3DIdentity 
    } 
} 

@IBAction func rightAction(sender: AnyObject) { 
    circleView.layer.transform = CATransform3DIdentity 
    UIView.animateWithDuration(0.5) { 
     self.circleView.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1) 
    } 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 

    circleView.backgroundColor = .blueColor() 
    circleView.layer.cornerRadius = CGRectGetMidY(circleView.bounds) 
} 

enter image description here