views:

48

answers:

2

Someone else asked a similar question previously, but I am interested in knowing whether the autorotate feature of the iPhone SDK will allow us to replace the rotation animation with another transition, such as a fade-in/fade-out. For a modal view, we can set the modalTransitionStyle but there is no such property for autorotate.

If I can't leverage the built-in functionality, how else can I implement this functionality?

A: 

There's the willAnimateRotationToInterfaceOrientation:duration: method, from the docs:

The default implementation of this method does nothing. If you override this method, you should not override either the willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: or willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration: method.

This method is called from within the animation block that is used to rotate the view. You can override this method and use it to configure additional animations that should occur during the view rotation. For example, you could use it to adjust the zoom level of your content, change the scroller position, or modify other animatable properties of your view.

I guess you can modify it from here, and before and after with – willRotateToInterfaceOrientation:duration: and – didRotateFromInterfaceOrientation:.

This seems inefficient and sub-par to me, as it does not actually replace the transition at all.

I would make a category on UIView, that includes methods such as -willRotateUsingTransition: and pass a parameter that will tell it to fade, then set the view's alpha to zero. In each subclass override this to include any subviews that need their alpha changed, if that is applicable. Call this method when the views are about to be rotated (with the methods above) and then a clean-up method that restore the alphas when they will appear again.

Edit: Docs Docs Docs. A quick look, again, reveals this method: - (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration, which I thought to be deprecated. As part of the discussion it has the text from the second paragraph I posted from the docs earlier.

JoePasq
I've tried to mangle with these a lot, including setAnimationDelay, one/two step animations, etc. and nothing will get rid of the actual rotation. Unfortunately, I understand that if I don't use the built-in autorotation feature, I don't get the benefits of the autoresizing controls I define in IB. Unfortunate.
Stride
Ah. That is unfortunate. Sorry.
JoePasq
A: 

I achieved something similar by attaching the auto-orientation behaviour to a hidden view, and responding the relevant events by implementing my own custom effect. It was quite fiddly, and I don't remember all the details, but I did manage to exercise complete control over the behaviour.

I should say, though, that in my case, I wanted to have control over how the rotation was implemented. I wanted the primary layout to remain fixed, while rotating several subviews in concert. I can't think of a good reason to completely replace the rotation with a fade-out-then-in; it'll just confuse users for no good reason. The only reason I can think of for using a fade effect is that you want to swap to a substantially different UI, but even then, there's no reason to suppress the rotation effect.

Marcelo Cantos
Whether there is a reason for suppressing the rotation effect is subjective, I think. Unfortunately, it seems there is no good technical method to suppress it.
Stride
@Stride: Dress-sense is subjective too, but no one wears undies on their head (or at least, if they do, they're generally not trying to put on a well-coordinated wardrobe). In any case, the technique I used of pointing to a hidden view does completely suppress the normal effect and lets you do whatever you want. I ended up with a view controller holding the relevant orientation methods, who's view was inside an unused top-level view (i.e., it wasn't under the main view tree for the XIB). I don't know if it needed the nested view, but by that time I was sick of tinkering, and it worked.
Marcelo Cantos
I won't tell you how to dress if you don't tell me how to dress.
Stride