开发者

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
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜