how do I detect the iPhone orientation before rotating

后端 未结 7 1746
忘了有多久
忘了有多久 2020-12-28 09:32

In my program I\'m moving things based on rotation, but I\'m not rotating the entire view. I\'m Using :

  static UIDeviceOrientation previousOrientation = U         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 09:48

    Mort, these answers seem somewhat of a red herring; I can't see why you can't use the following built-in method for a UIViewController class:

    -(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {}
    

    This method gets called automatically after a rotation has occurred (rather than with shouldAutorotateToInterfaceOrientation which only tells you it's about to happen). Handily, the variable 'fromInterfaceOrientation' contains the previous orientation. As the documentation also says, you can assume that the interfaceOrientation property of the view has already been set to the new orientation, so you then have one method with access to the old orientation and the new!

    If I've missed something and you've already dismissed being able to use this method, my apologies! It just seems odd that you're creating and storing a variable for the "previous orientation" when it's provided for free in the above method.

    Hope that helps!

提交回复
热议问题