iOS手机摇晃事件

- (BOOL)becomeFirstResponder{

    return YES; //是控制器成为第一响应

}


- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{

    NSLog(@"motionBegan"); //手机开始摇晃

}


- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{

    if (motion == UIEventSubtypeMotionShake) {

        NSLog(@"motionEnded"); //手机摇晃结束

    }

}


- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    NSLog(@"motionCancelled"); //取消摇晃

}


按control+command+z模拟真机的手机摇晃

你可能感兴趣的:(iOS手机摇晃事件)