检测晃动的三种方法
http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone
我的實現(基于Eran Talmor):
沒必要application.applicationSupportsShakeToEdit = YES;
Set theapplicationSupportsShakeToEditproperty in the App's Delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
application.applicationSupportsShakeToEdit = YES;
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- Add/Override canBecomeFirstResponder, viewDidAppear: and viewWillDisappear: methods in your View Controller (這個View controller必須是頂層的):
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
- Add the motionEnded or motionBegan method to your View Controller (模擬器中響應motionBegan, motionEnded,但真實機器iphone4中只能響應motionBegan):
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
// your code
}
}
轉載于:https://www.cnblogs.com/vinceoniphone/archive/2011/05/19/2051021.html
總結
- 上一篇: HDU2673-shǎ崽(水题)
- 下一篇: (转)linux下oracle inst