I am trying to understand how PaintCode animations can be intergated in Xcode. In my example I have a ball going from right to left. I want the animation to start as long as the app starts and stop when you stop the stop button. In the attachments is what i have done so far:
First thing that is wrong is that your drawBall
function is defined with an argument, but you never pass anything to it through the NSTimer
. You should use the userInfo
argument of the NSTimer
initialisation if you want to pass an argument to the timer fire function.
Second of all, your NSTimer
is trying to call the selector "drawBall"
, but your function is defined with an argument. Therefore it should be "drawBall:"
.
Third of all, I'm pretty sure the external argument name in your function is interfering with the selector name.
Try changing it to:
func drawBall(var fraction:CGFloat) {
...
}
It's also worth noting that you can define selectors in swift just by using the string literal syntax. Therefore you could just provide "drawBall:"
in your NSTimer
.
Furthermore, there are a few other things that you'll want to look into...
fraction
variable into your drawRect
methoddrawRect
method (do this though using setNeedsDisplay()
)