I am developing an application that measures the total time of a shake event. In other words, the timer starts when the shake event is started, and the timer stops when the shake event ends.
So my question is, if we hold two iTouches in a single hand and then shake both at the same time, will the shake event generate the same value on both iTouches?
This is my code:
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
timer = [NSTimer scheduledTimerWithTimeInterval:0.00025 target:self selector:@selector(showactivity) userInfo:nil repeats:YES];
}
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
[timer invalidate];
}
}
I’d just make an instance variable of type
NSDatecalledshakesBegan, or whatever. Then just call this inmotionBegan:The output should say something like
Shaken for 1.233242 seconds. However, I don’t have a device to test this so your mileage may vary.The reason you’re getting an error is because you must make
shakesBeganan instance variable. Like this in your interface: