调用手机摇一摇功能其实很简单,在你调用的控制器的
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(@"结束摇动");