2

那是我的代码。

-(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");
    }
}

我想在我的设备上摇晃/运动。我使用了该代码,但它不起作用..

4

1 回答 1

1

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

-(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];

}

让我知道它是否有效!

快乐编码!!!!

于 2013-08-17T05:29:12.273 回答