Question

Is it possible to delay or trigger auto rotation in any way in iOS 7, without switching to a new view controller?

Consider the example of Siri on iPad. When Siri is activated, the application running behind it is deferred and blurred with Siri's transparent interface laid over top. If you rotate the device while using Siri, nothing happens, but upon dismissing Siri, the auto rotation event finally fires.

I'm accomplishing a similar blur/defer effect in my application by taking a snapshot of the window, blurring/scaling it, placing it over top of the view being displayed, and placing additional transparent content over top. Because this is a snapshot and cannot resize on-the-fly, I prevent auto rotation from occurring (like Siri) with -shouldAutorotate returning NO high up in the view hierarchy. Once this state is dismissed, I once again allow auto rotation, but no rotation is triggered. This is because the rotation that occurred while the app was in this blur/defer mode was ignored.

Is it possible to trigger auto rotation to occur to properly rotate to the device's actual orientation after I return from this mode?

Was it helpful?

Solution

Here are my three suggestions:

  1. Use a live blur view and allow animation. There are many open-source implementations, most of which use a stretched toolbar or its blurring CALayer. This will allow you to support rotation as well as have a live view under the blurred background (like Siri). Edit: After digging around, I found out that certain open-source implementations, which were taking the CALayer of a toolbar were rejected by Apple. By taking a toolbar and stretching it seems safe.

  2. After taking a snapshot of the key window, display that snapshot as the root view of another window which is displayed above the key window. If I recall correctly, a view alone, without a view controller attached, will not rotate when added to the window's view hierarchy. (If it does, it is very easy to counter using a counter-transform.) In essence, you will achieve a non-rotating view. The window below will rotate normally, however. When dismissing the snapshot holding window, fade it out so that the view hierarchy below is smoothly presented to the user. Drawbacks of this approach is no live preview of the blurred background, the rotation animation will not be seen by the user.

  3. Rotation in iOS is basically the view controller setting a transform to the view, if all conditions are met and it is determined that interface rotation is supported. In the view controller responsible for the blurred view, counter rotation with inverted transforms. This should make views appear as if not rotating. Once it comes time to hide the blurred view, use an animation block to reset the transform, which will create the same animation as rotation. If you combine this approach with a live blur view, this will recreate the native Siri experience 1:1. Your only problem will be the status bar will rotate regardless of the view's transform, because it gets its transform from a different system. There are gray-area remedies for this.

These recommendations are sorted by ease of implementation. Each can be implemented by itself or a combination of 1+2, 1+3 or 1+2+3.

OTHER TIPS

Siri follows different rules. It is a whole different application (and a privileged system application at that) that is displaying on top of the previously frontmost application.

As for your situation, the thing to do is probably to present a full-screen modal view controller on top of the current view controller that only allows the current orientation. Then, when it's dismissed, the previous VC will allow rotation again and everything should pick up where it left off.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top