I wrote a simple view controller that shows a modal popup dialog. Because it creates a new window to lay over the entire screen, I've added a UIDeviceOrientationDidChangeNotification
observer that figures out how to rotate the view using CGAffineTransformMakeRotation()
. And it seems to work.
Mostly. The downside is that I can fiddle with the orientation and get it to end up sideways or upside down. Check out this 18s video demonstrating the issue. In debugging, it appears that sometimes the notification doesn't fire, or at least doesn't call the callback method that's listening for it.
I must be missing something, though, because if you look at the video again, you'll notice that the view behind it does rotate properly. That one is managed by -willAnimateRotationToInterfaceOrientation:duration:
. How is it that the iOS controller method is always called properly (presumably managed by a UIDeviceOrientationDidChangeNotification
observer in UIViewController) but my own code is not?
I fixed this problem by eliminating the use of UIDeviceOrientationDidChangeNotification
. What I do instead is create a subclass of UIViewController
and make set the custom view to its view. It then simply implements -willAnimateRotationToInterfaceOrientation:duration:
to do the rotation. This is actually less finicky code for me. It does feel like a hack, though, to create an arbitrary UIViewController
just to take advantage of autorotation in what is essentially a clone of presentModalViewController
. Seems like UIDeviceOrientationDidChangeNotification
ought to work properly. I expect there is a way to make it behave, but I've yet to find it. :-(