- (void)viewDidLoad
{
[superviewDidLoad];
/// 设置Controller支持摇动 [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES]; /// 同时让他成为第一相应者: [self becomeFirstResponder];}
/// 检测到摇动- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{}/// 摇动取消- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{}/// 摇动结束- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{ if (event.subtype == UIEventSubtypeMotionShake)
{ } }
本文介绍了一个iOS应用中实现摇动事件的方法。通过设置UIApplication支持摇动编辑,并让ViewController成为第一响应者,实现了对设备摇动的监听。文中详细展示了如何通过motionBegan、motionCancelled及motionEnded等方法来检测摇动开始、取消及结束的状态。
115

被折叠的 条评论
为什么被折叠?



