-1

I have an animation that deletes a circle in the UI and then recreates it somewhere else, but when I recreate it, it is smaller than what I want. I can't figure out why it is appearing smaller.

        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)
}

I have tried removing all the animations among other things but it always appears smaller. Any help on why this happens would be great.

Here is how it looks the first time createCircle() is called.

enter image description here

This is how it looks when it is called from the animation.

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141
Taylor
  • 733
  • 7
  • 18
  • I was having a hard time uploading pictures of before and after, but here is a dropbox link. The one with the big dot is how it looks the first time createCircle() is called while the other picture is how it looks when it is called from the animation. https://www.dropbox.com/sh/bccvdfnrjgou2tp/AABZYmswSlwkXimAHG_dQ9tYa?dl=0 – Taylor Jul 31 '16 at 00:18
  • I was putting in the removeAllAnimations and removeFromSuperview to see if those would fix it but they didn't. As far as I know, the createCircle() doesn't create it each time. The variable circle is called outside of all the functions in the viewController so I can edit them in other functions than where they are created. Each time I recreate them, I think they are being edited from what they were previously. – Taylor Jul 31 '16 at 00:45
  • How do I find fix it? – Taylor Jul 31 '16 at 00:50

1 Answers1

0

I think is enough to set removedOnCompletion to true, so CAAnimation will reset to original size. Give a try ! :)

ingconti
  • 10,876
  • 3
  • 61
  • 48