iphone 接收摇动事件

关键词: ios iphone shake gesture UIView

在 ios3.0 之后, UIView 提供了三个函数接收摇动事件

motionBegan:

motionEnded:

motionCancelled:

只需要继承 UIView 并实现以上函数即可.

需要注意的事项:

1. 这个UIView 要成为事件响应者, 也就是显示之后 becomeFirstResponder

2. 更加重要! 这个 UIView 要实现 canBecomeFirstResponder 函数并且返回 YES. 否则上一条建议无效.

 

参考资料: http://www.iphonedevsdk.com/forum/iphone-sdk-development/4381-iphone-shaking-code.html

motionBegan: motionEnded: motionCancelled:

posted on 2012-06-11 01:47  大宝pku  阅读(402)  评论(0编辑  收藏  举报

导航