【发布时间】:2011-04-03 22:03:33
【问题描述】:
我无法在 iPhone 上获取震动事件。
我在这里关注了其他问题,但没有结果。我也尝试遵循 Apple 的 GLPaint 示例,但它看起来与我的源代码完全一样,只是略有不同。 GLPaint的源代码/works/,我的/doesn't/。
所以,这就是我所拥有的:
控制器.m
- (void)awakeFromNib {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shakeEnded) name:@"shake" object:nil];
}
ShakingEnabledWindow.m
- (void)shakeEnded {
NSLog(@"Shaking ended.");
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake ) {
// User was shaking the device. Post a notification named "shake".
[[NSNotificationCenter defaultCenter] postNotificationName:@"shake" object:self];
NSLog(@"Shaken!");
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
}
我的 XIB 有一个窗口,它是一个 ShakingEnabledWindow 和一个对象,我的控制器。
我的想法已经不多了,希望有人能帮帮我。 :)
【问题讨论】:
-
您是否想让它与
View或ViewController一起使用?
标签: iphone cocoa-touch shake motion-detection