iphone simulator shaking has no function
Hello everyone I hoped to test the shaking functio开发者_JS百科n on simulator, so in the Hardware menu, I choose Shake Gesture. But nothing happened, what wrong?
Welcome any comment
Thanks
Marc
Clicking "Shake Gesture" in the iPhone simulator doesn't play an animation—perhaps this is why it seems not to be doing anything?
You can receive notification of shake events in your code by implementing motionEnded:withEvent:
in a UIResponder
subclass. For example, if you were to create a custom UIWindow
subclass:
// ShakeWindow.h
@interface ShakeWindow : UIWindow
@end
// ShakeWindow.m
#import "ShakeWindow.h"
@implementation ShakeWindow
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
NSLog(@"Shake!");
}
}
@end
For more information, see the Motion Events section of Apple's Event Handling Guide for iOS.
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
NSLog(@"shake");
//your code
}
}
精彩评论