源码简介:iPhone上的摇一摇实现很简单。具体参考下面的代码或者下载Demo试一下。
源码效果:
源码片段:
- #pragma mark - 摇动
- /**
- * 摇动开始
- */
- - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
- if (motion == UIEventSubtypeMotionShake) {
- NSLog(@"开始摇了");
- }
- }
- /**
- * 摇动结束
- */
- - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
- NSLog(@"摇动结束");
- }
- /**
- * 摇动取消
- */
- - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
- NSLog(@"摇动取消");
- }