I have been working on this for a few days with no luck... I am using Interface Builder to build the views. I have a UIButton with an image as the background. When I shake the iPhone, I want the button to wiggle. Any ideas?
Asked
Active
Viewed 7,774 times
2
-
You say that you've been trying it for a few days? What have you tried? Devin Ceartas's response should work – hhafez Jul 06 '09 at 04:38
-
Tried to work with a response directed toward OS X using CGRect and shaking a login window. Could not get it to work on the iPhone because of the CGRect integration. Going to try the response listed above. I'll post on how it works. – iPhone Guy Jul 06 '09 at 15:22
-
Possible duplicate of [how to create iphone's wobbling icon effect?](http://stackoverflow.com/questions/929364/how-to-create-iphones-wobbling-icon-effect) – Daniel Storm Oct 17 '15 at 14:35
2 Answers
3
Wobbling effect code here: how to create iphone's wobbling icon effect?.
There are examples of shake detection in Apple sample code so I won't repeat it here. You'll want to set a threshold for how hard you want it shaken (and maybe in what direction, if you care). Once it reaches that point then just trigger the routine that kicks off the animation effect. You may want to turn off shake detection once it's started and then turn it back on in the animation completion handler.
-
In the 3.0 API, shake detection is built in. If you want the app to work on older versions of the OS, use the snippet here: http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone – Felixyz Jul 06 '09 at 10:51
0
I presume you'd have to change the CGRect defining the frame in which the button is drawn.

Devin Ceartas
- 4,743
- 1
- 20
- 33