摇摇功能的实现

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

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

例子:

#import "XJViewController.h"


@interface XJViewController ()


@end


@implementation XJViewController



// 开始摇

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

{

    NSLog(@"开始摇");

}

// 摇晃结束

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

{

    NSLog(@"摇晃结束");


}

// 摇晃取消(被打断:打电话)

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

{

    NSLog(@"摇晃取消");

}

posted @ 2014-08-27 23:26  h@xj  阅读(146)  评论(0)    收藏  举报