I've got a request to make a fidget spinner animation inside one shopping app, its meant to give the user a 'feel' before clicking buy so its a UIImageView
that needs to be animated. I've added a custom single touch gesture recognizer that allows the user to spin/rotate the view, however the image now only rotates and stops as soon as the user lets go, what would be the best way to keep the 'velocity' going? Think of how something would be done with SpriteKit?
Asked
Active
Viewed 697 times
0

Sam Bing
- 2,794
- 1
- 19
- 29
-
1. You should use Core Animation, not SpriteKit, 2. Show your tried code – Papershine May 17 '17 at 12:24
-
I am not using SpriteKit i was just thinking how i would achieve something similar with core animation. – Sam Bing May 17 '17 at 12:25
-
1I have answered something similar to your query [here](http://stackoverflow.com/a/33821933/4447772) – aashish tamsya May 17 '17 at 12:31
-
Thanks I will check it out. – Sam Bing May 17 '17 at 12:37
-
1Angular velocity and angular momentum are things that you will be looking for – Alec O May 17 '17 at 17:15
-
Thank you @AlecO that was really helpful. – Sam Bing May 24 '17 at 16:56
1 Answers
1
I left a comment regarding angular velocity and momentum but wanted to answer this question so the next person who needs help knows a way to do this.
Angular velocity is the speed of the spinning. What you want to do is apply an angular impulse which will start the spinning. The mass and angular momentum will slow it down as time passes, just like the actual physics behind the fidget spinners.
Add this to the touchesBegan
method in the fidgetSpinner
class
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
fidgetSpinner.physicsBody?.applyAngularImpulse(1)
}
Or add it to the scene but check that the touch was inside and on fidgetSpinner
.
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first?.location(in: self)
if fidgetSpinner?.contains(touch) {
fidgetSpinner.physicsBody?.applyAngularImpulse(5)
}
}

Alec O
- 1,697
- 1
- 18
- 31
-
This works on SpriteKit although my question was achieving the effect without SpriteKit, although the same applies. – Sam Bing May 26 '17 at 07:08
-
You had mentioned that my comment was helpful, and my comment spoke of angular velocity and momentum. Both are concepts in SpriteKit, and ones that may be helpful to people looking for a solution in the future. – Alec O May 26 '17 at 10:13
-
I didn't claim it wouldn't be, and your comment certainly was helpful, angular momentum and angular velocity were helpful as i emulated them without SpriteKit. Hence i also up-voted your answer. – Sam Bing May 26 '17 at 13:04