那是我的代码。

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(shake) name:@"shake" object:nil];
    if(event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake)
    {

       // SOMETHING HERE
    }
            NSLog(@"motion Began");
    }
     else
    {
        NSLog(@"Shake Is Over");
    }
}

我想在设备上摇动/移动。我使用了该代码,但无法正常工作。

最佳答案

写下下面的代码...然后检查

-(BOOL) canBecomeFirstResponder {

return YES;

}

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

}

-(void)viewDidAppear:(BOOL)animated {

[self becomeFirstResponder];

}

-(void)viewDidDisappear:(BOOL)animated {

[self resignFirstResponder];

}

让我知道它是否有效!!!

编码愉快!!!

关于iphone - 我无法在设备上摇动/移动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18285350/

10-12 14:49