Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
震动检测iPhone 3.0不工作_Iphone_Events_Triggers_Detection_Shake - Fatal编程技术网

震动检测iPhone 3.0不工作

震动检测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

我有一个ViewController,它与触发动作的按钮完美配合。我想用一个震动事件替换这个按钮,所以我在谷歌上搜索了一下,并创建了一个震动检测器类,它在UIView中显示

我的实施情况如下:

@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中写入它