Simple iPhone motion detect

前端 未结 2 1655
逝去的感伤
逝去的感伤 2020-11-28 08:09

I need to detect when the gyroscope / accelerometer is activated a certain amount. Basically to detect when there is movement of the device. I don\'t know anything about Cor

2条回答
  •  难免孤独
    2020-11-28 08:51

    In viewDidAppear, become the first responder:

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

    And make sure you can be first responder:

    - (BOOL)canBecomeFirstResponder {
        return YES;
    }
    

    Then you can implement the motion detection.

    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        if (event.subtype == UIEventTypeMotion){
            //there was motion
        }
    }
    

提交回复
热议问题