Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

iphone shaking code

mekmek Posts: 8New Users
edited February 2010 in iPhone SDK Development
iphone shaking code

ive looked around quite a bit, and can't seem to find any examples of code to perform an action if the iphone is shaken

has anyone been able to successfully do this? if so how
i would imagine you would monitor the accelerometer for changes in x,y,and,z

maybe?
<code>
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
const float earthquake = 1.5;
static BOOL shakeme;
BOOL shake = FALSE;

if (shakeme) return;
beenhere = TRUE;
if (acceleration.x > earthquake || acceleration.x < (-1* earthquake))
shake = TRUE;
if (acceleration.y > earthquake || acceleration.y < (-1* earthquake))
shake = TRUE;
if (acceleration.z > earthquake || acceleration.z < (-1* earthquake))
shake = TRUE;
if (shake) { /* perform action here */ }

shakeme = false;
}
</code>
so if the action that you wanted to perform was to pull a random object/data from a sqlite3 database, it would be some rand code that randomized the Primary key, and whatever that value is ...send that data to the view or a label or imagecontroller

i dunno

any ideas?
Post edited by mek on

Replies

Sign In or Register to comment.