我无法在我的设备上摇动/运动

时间:2013-08-17 05:10:45

标签: iphone ios ios4

这是我的代码。

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

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

1 个答案:

答案 0 :(得分: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];

}

让我知道它的工作与否!!!

快乐编码!!!!