Kodeco Forums

PaintCode Tutorial for Developers: Getting Started

In this PaintCode tutorial for beginners, learn how to animate a stopwatch control created in PaintCode!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1822-paintcode-tutorial-for-developers-getting-started

Note that switching away from the “Asset” tab and back repeatedly causes the animation to speed up faster and faster, which seems like an infinite loop (?) occurs. This can be prevented by calling ‘self.rotateStopWatchHand()’ only if ‘finished’ is true. Try this code without the ‘if’ statement to see the speedup occur (you’ll see the transform count rapidly increasing in the debug console output). Hope this helps someone else who may have noticed this!

class AssetViewController: UIViewController {
    @IBOutlet weak var stopWatchHandView: UIView!
    var transformCount = 0
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        rotateStopWatchHand()
    }
    
    func rotateStopWatchHand() {
        UIView.animateWithDuration(
            4.0,
            delay: 0,
            options: .CurveLinear,
            animations: {
                self.stopWatchHandView!.transform = CGAffineTransformRotate(self.stopWatchHandView!.transform, CGFloat(M_PI_2))
            },
            completion: { finished in
                if finished == true {
                    self.rotateStopWatchHand()
                    self.transformCount += 1
                    print("\(self.transformCount) - animation ended.")
                }
            }
        )
    }
}

Any chance this will be updated? Ran into an error regarding problems with CGAffineTransformRotate in the latest Xcode and Swift. Not sure how to fix.

I’m not 100% sure about this tutorial being updated, or when.

This particular one is no longer supported as it’s over a year old, so there may be issues with compatibility on the latest of available tools :slight_smile:

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]