猿问

第一次摇动的时候有相应,会执行到代码A;但是再摇就不管用了,请问为什么?

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{    if(motion==UIEventSubtypeMotionShake)
    {
        代码A
    }
}

-(BOOL)canBecomeFirstResponder{    return YES;
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [self resignFirstResponder];
    [super viewWillDisappear:animated];
}


临摹微笑
浏览 116回答 1
1回答

鸿蒙传说

如果你要响应多次,建议使用UIAccelerometer- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {     if (fabsf(acceleration.x) > 1.0 || fabsf(acceleration.y) > 1.0 || fabsf(acceleration.z) > 1.0) {         代码A     } }
随时随地看视频慕课网APP

相关分类

iOS
我要回答