iOS 手机摇一摇功能

调用手机摇一摇功能其实很简单,在你调用的控制器的

viewDidLoad方法里调用

[UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;

方法即可,当手机摇一摇的时候会有代理回调方法:

- (void)viewDidLoad {

    [super viewDidLoad];

    [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;//调用这个方法就行

}

#pragma mark - - - 摇一摇的相关方法

//开始摇动

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

{

    NSLog(@"开始摇动");

}

 

//取消摇动

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

{

    NSLog(@"取消摇动");

    

}

//结束摇一摇

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

{

    NSLog(@"结束摇动");

}

 

posted @ 2016-09-06 15:24  鹰在北方  阅读(672)  评论(0)    收藏  举报