iPhone摇一摇

监控摇一摇的方法
方法 1 :通过分析加速计数据来判断是否进行了摇一摇操作(比较复杂)
方法 2 iOS 自带的 Shake 监控 API (非常简单)

判断摇一摇的步骤 实现 3 个摇一摇监听方法
-( void)motionBegan:( UIEventSubtype)motionwithEvent:( UIEvent*)event /** 检测到摇动 * /
-( void)motionCancelled:( UIEventSubtype)motionwithEvent:( UIEvent*)event /** 摇动取消 ( 被中断 )*/
-( void)motionEnded:( UIEventSubtype)motionwithEvent:( UIEvent*)event /** 摇动结束 * /
//
//  ViewController.m


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    NSLog(@"用户摇一摇");
}

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    // 摇一摇被打断(电话)
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    // 摇一摇结束
}

@end


你可能感兴趣的:(iPhone摇一摇)