转自:
把下边的代码 放到UIVIEWCONTROLLER里,就能实现摇一摇效果
- #pragma mark - Shake
- - (BOOL) canBecomeFirstResponder
- {
- return YES;
- }
- - (void) viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- [self becomeFirstResponder];
- }
- - (void) viewWillAppear:(BOOL)animated
- {
- [self resignFirstResponder];
- [super viewWillAppear:animated];
- }
- - (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
- {
- if (motion == UIEventSubtypeMotionShake) {
- NSLog(@"Shake..........");
- }
- }
使用这段代码需要注意的是,如果ViewController不是FirstResponder的话,那么当前窗口就得到摇一摇的动作。
可以将montionBegan的事件,放到UIWindos中会更好一些
全站熱搜
留言列表