摇一摇是利用了手机自带的加速器,利用一些算法,但是苹果已经集成的一个功能,只需在AppDelegate中重写下面的三个方法即可:
/**
* 开始摇晃就会调用
*/
- (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__);
}