控制器中.m的实现
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//微信的摇一摇是怎么实现的~发现原来 ios本身就支持
//在 UIResponder中存在这么一套方法,只需要在相关方法中做处理即可
[[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];
[self becomeFirstResponder];// 让控制器成为第一响应者,支持摇动
}
/**
* 开始摇晃就会调用
*/
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"%s", __func__);
}
/**
* 摇晃结束就会调用
*/
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"%s", __func__);
}
/**
* 摇晃被打断就会调用
*/
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
NSLog(@"%s", __func__);
}
@end