Detecting iOS orientation change instantly

后端 未结 6 2148
忘掉有多难
忘掉有多难 2020-12-02 05:38

I have a game in which the orientation of the device affects the state of the game. The user must quickly switch between Landscape, Portrait, and Reverse Landscape orientati

6条回答
  •  Happy的楠姐
    2020-12-02 06:41

    That delay you're talking about is actually a filter to prevent false (unwanted) orientation change notifications.

    For instant recognition of device orientation change you're just gonna have to monitor the accelerometer yourself.

    Accelerometer measures acceleration (gravity included) in all 3 axes so you shouldn't have any problems in figuring out the actual orientation.

    Some code to start working with accelerometer can be found here:

    How to make an iPhone App – Part 5: The Accelerometer

    And this nice blog covers the math part:

    Using the Accelerometer

提交回复
热议问题