//摇动检测 // 1. add/Override canBecomeFirstResponder, viewDidAppear 和 viewWillAppear - (BOOL) canBecomeFirstResponder { return YES; } - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self becomeFirstResponder]; } - (void) viewWillAppear:(BOOL)animated { [self resignFirstResponder]; [super viewWillAppear:animated]; } //2. Add motionBegan or motionEnded 方法到你的View Controller (模拟器中二者都可以响应, 真机iphone4中只能相应motionBegan) - (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion == UIEventSubtypeMotionShake) { [self shaked]; } }
转载于:https://www.cnblogs.com/wanyakun/archive/2012/05/10/3403300.html