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:
1 Answers
A few things are wrong here
- First thing that is wrong is that your - drawBallfunction is defined with an argument, but you never pass anything to it through the- NSTimer. You should use the- userInfoargument of the- NSTimerinitialisation if you want to pass an argument to the timer fire function.
- Second of all, your - NSTimeris 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...
- You never pass the fractionvariable into yourdrawRectmethod
- You never invoke your drawRectmethod (do this though usingsetNeedsDisplay())
- 
                    try changing the function to `func drawBall(var fraction:CGFloat)` – Hamish Jan 21 '16 at 13:52
- 
                    Sorry for some reason only the last two lines of your response appeared before. I have provided "drawBall:" in the NSTimer and changed the function to func drawBall(var fraction:CGFloat) . I do not get any crushes now, but as you can guess the ball doesn't move. I am not sure how to use the userInfo argument of the NSTimer initialisation in order to pass an argument, i tried userInfo: ("fraction") but it didnt work.. – Do2 Jan 21 '16 at 14:25
- 
                    no, `userInfo` takes an object, not a primative time like `CGFloat`... what are you using the `fraction` variable for anyway? to me it looks like something that should be an instance variable (up with the `timer` and `counter` variables) – Hamish Jan 21 '16 at 14:29
- 
                    okay... well you're never passing it into the `UIView`'s `drawRect`.. I think you want to move your animation logic into the `UIView` (including the timer), make the fraction variable an instance variable, and pass the fraction variable into the `drawBall` function (in the StyleKitName2 class) – Hamish Jan 21 '16 at 14:41
- 
                    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/101315/discussion-between-originaluser2-and-do2). – Hamish Jan 21 '16 at 14:53




 
     
     
    