iPhone模拟器摇晃没有任何功能

时间:2011-03-20 10:58:15

标签: iphone ios-simulator

大家好 我希望在模拟器上测试抖动功能, 所以在硬件菜单中,我选择了Shake Gesture。 但什么都没发生,有什么不对?

欢迎任何评论

由于

马克

2 个答案:

答案 0 :(得分:0)

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    if (motion == UIEventSubtypeMotionShake) {
        NSLog(@"shake");
        //your code
    }

}

答案 1 :(得分:0)

点击iPhone模拟器中的“Shake Gesture”不会播放动画 - 也许这就是为什么它似乎没有做任何事情?

您可以通过在motionEnded:withEvent:子类中实施UIResponder来接收代码中震动事件的通知。例如,如果您要创建自定义UIWindow子类:

// 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

有关详细信息,请参阅Apple的iOS事件处理指南的Motion Events部分。