开发者

Couldn't detect device's shakes

开发者 https://www.devze.com 2023-02-18 17:47 出处:网络
I\'m trying to detect when the device(iPhone/iPod Touch) shakes, what I have already done (in my viewController.m) is :

I'm trying to detect when the device(iPhone/iPod Touch) shakes, what I have already done (in my viewController.m) is :

- (BOOL) canBecomeFirstResponder{
return YES;
}

.

- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (motion == UIEventSubtypeMotionShake){
NSLog(@"Motion detected");
}
}

and 开发者_JS百科I've added this line to viewDidLoad :

BOOL ret = [self becomeFirstResponder];

Then, I build&ran the app, and tried to shake the device but nothing happened!.. I started troubleshooting the problem, by using Breakpoints, what I detected is that the "ret" value returned from [self becomeFirstResponder] is "NO". And couldn't know what is the problem. Any help ?

Info : using Xcode 4, and iOS 4.3

Thanks in advance.


Have you looked at Shaking-Motion Events?


I actually found the solution..

[self becomeFirstResponder];

should be only implemented in viewDidAppear: because I tried it in viewWillAppear: and viewDidLoad and it's not working in the both methods.

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号