震动检测iPhone 3.0不工作
我有一个ViewController,它与触发动作的按钮完美配合。我想用一个震动事件替换这个按钮,所以我在谷歌上搜索了一下,并创建了一个震动检测器类,它在UIView中显示 我的实施情况如下:震动检测iPhone 3.0不工作,iphone,events,triggers,detection,shake,Iphone,Events,Triggers,Detection,Shake,我有一个ViewController,它与触发动作的按钮完美配合。我想用一个震动事件替换这个按钮,所以我在谷歌上搜索了一下,并创建了一个震动检测器类,它在UIView中显示 我的实施情况如下: @implementation ShakeDetector - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { } - (void)motionEnded:(UIEventSub
@implementation ShakeDetector
- (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:@"spin" object:self];
NSLog(@"sss");
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
@end
但我不能让它工作。。。有什么帮助吗
谢谢放:
-(BOOL)canBecomeFirstResponder
{
return YES;
}
请注意:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
[super viewDidDisappear:animated];
}
您也可以在VIEWWILLEXPEND和VIEWWILLEXPEND中写入它