2016-07-31 68 views
-1

我有一個動畫,刪除用戶界面中的一個圓圈,然後在其他地方重新創建它,但是當我重新創建它時,它比我想要的要小。我無法弄清楚它爲什麼顯得更小。Swift - 刪除動畫效果

 let viewsToAnimate = [circleFrame] 

     UIView.perform(UISystemAnimation.delete, on: viewsToAnimate, options: [], animations: { 

      }, completion: { finished in 
       self.circle.removeFromSuperlayer() 
       self.circleFrame.removeFromSuperview() 
       self.circleFrame.layer.removeAllAnimations() 
       self.createCircle() 
       self.score = self.score + 1 

       self.scoreLabel.text = "Taps: " + String(self.score) 
       self.tapsLabel.text = "Taps: " + String(self.initialTaps + self.score) 
     }) 



func createCircle() { 
    let randomX = generateRandomX() 
    let randomY = generateRandomY() 

    circleCenter = generateCircleCenter(x: randomX, y: randomY) 

    circleFrame.frame = CGRect(x: randomX, y: randomY, width: 100, height: 100) 
    circleFrame.alpha = 1.0 

    self.view.addSubview(circleFrame) 

    circle.path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 100, height: 100), cornerRadius: 50).cgPath 
    circle.fillColor = UIColor(red: 0, green: greenValue/255, blue: 0.6, alpha: 1.0).cgColor 
    circle.strokeColor = UIColor(red: 1, green: greenValue/255, blue: 0, alpha: 1.0).cgColor 
    circle.lineWidth = 0 

    circleFrame.layer.addSublayer(circle) 
} 

我試過除去其他東西中的所有動畫,但它總是顯得更小。任何有關爲什麼會發生這種情況的幫助將會很棒

下面是第一次調用createCircle()的樣子。

enter image description here

這是它的外觀時,它是從動畫調用。

enter image description here

+0

我很難上傳前後的圖片,但這裏是一個保管箱鏈接。帶有大圓點的那個是第一次調用createCircle()時的外觀,而另一張圖片是從動畫調用它時的樣子。 https://www.dropbox.com/sh/bccvdfnrjgou2tp/AABZYmswSlwkXimAHG_dQ9tYa?dl=0 – Taylor

+0

我正在把removeAllAnimations和removeFromSuperview看看是否會修復它,但他們沒有。據我所知,createCircle()不會每次都創建它。變量圓在viewController中的所有函數之外調用,所以我可以在其他函數中編輯它們,而不是在創建它們的位置。每次我重新創建它們時,我都認爲它們正在從之前的版本進行編輯。 – Taylor

+0

我如何找到修復它? – Taylor

回答

0

我認爲是不夠removedOnCompletion設置爲true,那麼CAAnimation將恢復到原來的大小。 試試吧! :)