- (void)viewDidLoad { [super viewDidLoad]; [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];//设置摇一摇时是否支持redo和undo操作,缺省时为yes,所以这句可以不写 [self becomeFirstResponder];//将当前控制器设置为第一响应者,只有第一响应者能够响应摇一摇的触发事件}//开始摇一摇时的响应方法- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"开始摇一摇");}//取消摇一摇时的响应方法(例如有电话打进来取消了摇一摇)- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { NSLog(@"取消摇一摇");}//摇一摇结束时的响应方法- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion != UIEventSubtypeMotionShake) { //判断手势是否是晃动手势 return; } self.view.backgroundColor = [UIColor redColor]; NSLog(@"摇一摇结束");}