我想在我的应用程序中使用"Shake Device"事件 - 即,当用户摇动设备时会发生一些事情.我试着实施:
-(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake) {
//something happens
}
}
Run Code Online (Sandbox Code Playgroud)
它似乎不起作用.......
有谁知道我应该使用哪种方法?
尝试使用下面的代码,它对我来说很好.
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if ( event.subtype == UIEventSubtypeMotionShake )
{
//your code
}
if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
[super motionEnded:motion withEvent:event];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6995 次 |
| 最近记录: |