iOS:如何实现“摇动设备”事件?
我想为我的应用程序添加“摇动设备”事件 - 即,当用户摇动设备时会发生一些事情。 我尝试实施:
-(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake) {
//something happens
}
}
它似乎不起作用......
有谁知道我应该使用哪种方法?
I want to a "Shake Device" event to my app - i.e., when the user shakes the device something happens.
I tried implementing:
-(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake) {
//something happens
}
}
It doesn't seem to work.......
Does anyone knows which method I should use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用下面的代码,它对我来说效果很好。
Try using the below code, it worked fine for me.
可能来不及回答,但在您的 viewDidLoad 中您需要包含。
尝试一下。
Might be to late to answer but in your viewDidLoad you need to include.
Give that a try.
除了 Taylor 的解决方案之外,还要确保您的 AppDelegate.m 中包含此解决方案。
In addition to Taylor's solution, also make sure that your AppDelegate.m has this in it.