views:

1293

answers:

3

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?

A: 

I presume you'd have to change the CGRect defining the frame in which the button is drawn.

Devin Ceartas
A: 

You say that you've been trying it for a few days? What have you tried?

Devin Ceartas's response should work

hhafez
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
+1  A: 

Wobbling effect code here: http://stackoverflow.com/questions/929364/how-to-create-iphones-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.

Ramin
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