DanM
DanM

Reputation: 7197

iPhone/iOS SDK: How to make certain subviews autorotate?

I've got an app that has two parts. Basically, the first part shows a bunch of image thumbnails. When you tap an image thumbnail, a full view of that image pops up inside a UIScrollView, filling the screen, with some buttons on top of it for performing various actions.

I want the main page with the thumbnails to always be in Portrait mode. But I want the two subviews -- the scrollview containing the image, and the uiview containing the buttons -- to autorotate when the user switches orientations.

I've tried having the View Controller for the main view return NO for the shouldAutorotateToInterfaceOrientation method, and then having the two subviews' controllers return YES, but then NOTHING rotates.

Is it possible to have only those two subviews respond to rotation events? How?

Upvotes: 1

Views: 1585

Answers (2)

AechoLiu
AechoLiu

Reputation: 18378

I think you can register as an observer for this notification, UIApplicationWillChangeStatusBarOrientationNotification

This notification is in the UIApplication Class Reference. When the application is about to change the orientation of its interface, the notification is posted.

Upvotes: 1

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

How are you presenting the scroll view and buttons? Strictly speaking, they should be managed by the same controller, presented modally over your first view controller. The autorotation system relies on whatever it thinks is the "main" view controller, which, in this case—assuming you're not actually using -presentModalViewController:animated:, as it doesn't sound like you are—remains the controller that's displaying the thumbnails. In other words: have one view controller set up the scroll view containing the full image and the action buttons, and, when the user taps a thumbnail in the main view, present that view controller.

Upvotes: 1

Related Questions