Detecting iOS UIDevice orientation

后端 未结 8 939
一生所求
一生所求 2020-11-28 03:29

I need to detect when the device is in portrait orientation so that I can fire off a special animation. But I do not want my view to autorotate.

How do I override a

8条回答
  •  感动是毒
    2020-11-28 04:17

    First disable all but the orientation you want (so that it doesnt rotate)

    Then like David said just get the device current orientation:

    https://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MotionEvents/MotionEvents.html

    Alternatively you can just use the accelerometer yourself (since its how it is done anyway) and check where the gravity is at to see what orientation it has. If you take this approach you can play with the values yourself to get different results.

提交回复
热议问题