Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude UIView from animating on autorotation

TL;DR

Need to keep autorotation, but exclude one UIView from autorotating on orientation change, how?

Back story

I need to keep a UIView stationary during the animation accompanied by autorotation (which happens on orientation change). Similar to how the iOS camera app handles the rotation (i.e controls rotate in their place).

Things I've tried

  • Returning false from shouldAutorotate(), subscribing to UIDeviceOrientationDidChangeNotification, and trying to manually handle the rotation event for each view separately.

    Works well if you don't need to change any of your UIViews' places, otherwise it's a pain figuring out where it should end up and how to get it there

  • Placing a non rotating UIWindow under the main UIWindow, and setting the main UIWindow background colour to clear.

    This works well if it's only one item, but I don't want to manage a bunch of UIWindows

  • Inverse rotation I.e rotating the UIView in the opposite direction to the rotation. Not reliable, and looks weird, it's also vertigo inducing

  • Overriding the animation in the viewWillTransitionToSize method. Failed

  • And a bunch of other things that would be difficult to list here, but they all failed.

Question

Can this be done? if so, how?

I'm supporting iOS8+


Update This is how the views should layout/orient given @Casey's example:

enter image description here

like image 601
MrHaze Avatar asked Oct 31 '22 10:10

MrHaze


1 Answers

I have faced with same problem and found example from Apple, which helps to prevent UIView from rotation: https://developer.apple.com/library/ios/qa/qa1890/_index.html

However, if UIView is not placed in the center of the screen, you should handle new position manually.

like image 76
Ponf Avatar answered Nov 15 '22 06:11

Ponf