Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6555067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:46:28+00:00 2026-05-25T12:46:28+00:00

I have a nested view hierarchy for an iPad application that supports orientation changes.

  • 0

I have a nested view hierarchy for an iPad application that supports orientation changes. It looks similiar to the following.

UIViewController
    UIView
        - UIView
            - UIImageView (disable rotation)
            - UIImageView
            - UIView (disable rotation)
        - UIView
        - UIView
        ...

I would like to lock the orientation for some of my subviews, while allowing others to auto-rotate and resize. I can’t quite seem to figure out how to accomplish this.

One approach seems to be rotating the subviews manually within willAnimateRotationToInterfaceOrientation:. That’s not particularly attractive given the SDK is executing a rotation that I would just be undoing.

Is there a way to simply disable orientation changes for subviews or some other method to restructure my hierarchy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:46:28+00:00Added an answer on May 25, 2026 at 12:46 pm

    Autorotation is handled by a view’s UIViewController (shouldAutorotateToInterfaceOrientation:), so one approach is to arrange your hierarchy such that rotatable views are managed by one view controller, and non-rotatable views by another view controller. Both of these UIViewController’s root views then need adding to the window/superview.

    The subtlety here is that if you have two view controller’s views on the same level (i.e. added via addSubview:), only the first view controller (usually the window’s rootViewController) will receive the shouldAutorotateToInterfaceOrientation: message.

    I used this approach myself to achieve a toolbar that rotates, while the main view does not.

    Apple’s Technical Q&A QA1688 (“Why won’t my UIViewController rotate with the device?”) talks a little bit about this issue.

    Update for iOS 6:

    Autorotation now uses UIViewController‘s shouldAutorotate and supportedInterfaceOrientations methods. shouldAutorotate returns YES by default, but remember that a view controller other than the rootViewController whose view is a direct subview of the window will NOT receive rotation callbacks anyway.


    Sample Code for iOS 6:

    Create a new project using the “Single View Application” template, and ensure “Use Storyboards” is checked. We’ll use the provided ViewController class as the rotating view controller (rename it if you like!), and create a second UIViewController subclass called NonRotatingViewController. Although this view controller will never even receive the rotation callbacks, for completeness and clarity add the following code in NonRotatingViewController.m:

    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    

    In the MainStoryboard file, drag out a new view controller object and set its class to NonRotatingViewController, and set its Storyboard ID to “NonRotatingVC”. While you’re there, change the rotating view controller view’s background color to clear (the non rotating view will be added underneath this one), and add a label to each view. In AppDelegate.m, add the following code:

    #import "NonRotatingViewController.h"
    
    // ...
    // ...
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        NonRotatingViewController *nonRotatingVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"NonRotatingVC"];
        [self.window addSubview:nonRotatingVC.view];
        return YES;
    }
    

    This is just instantiating a non rotating view controller and adding its view directly to the window (N.B. at this point the window’s rootViewController has already been set by the storyboard).

    Run the project. Rotate the device and marvel at the sight of one label rotating while the other stays still!


    Sample Code pre iOS 6:

    I did this in a new project – a new View-based Application will do just fine. Add two new view controllers: RotatingViewController and NonRotatingViewController. Inside each of their nibs I just added a label to describe whether the view should rotate or not. Add the following code:

    ‘RotatingViewController.m‘

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    

    ‘NonRotatingViewController.m‘

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if (interfaceOrientation == UIInterfaceOrientationPortrait) {    // Or whatever orientation it will be presented in.
            return YES;
        }
        return NO;
    }
    

    ‘AppDelegate.m‘

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        RotatingViewController *rotating = [[RotatingViewController alloc] initWithNibName:@"RotatingViewController" bundle:nil];
        self.rotatingViewController = rotating;
        [rotating release];
    
        NonRotatingViewController *nonRotating = [[NonRotatingViewController alloc] initWithNibName:@"NonRotatingViewController" bundle:nil];
        self.nonRotatingViewController = nonRotating;
        [nonRotating release];
    
        [self.window addSubview:self.rotatingViewController.view];
        [self.window insertSubview:self.nonRotatingViewController.view belowSubview:self.rotatingViewController.view];
    
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view model that looks like this: public class VenueIndexViewModel : BaseViewModel
I have some nested view models that implement INotifyPropertyChanged . I'd like to bind
I have defined a nested grid view in the following way. <asp:GridView ID=GridView1 runat=server
I have the same problem outlined here . That is, nested view models in
So I have things nested like this in a nib: UIViewController | |-UIView (container
I have a view that contains nested views of the same type. Because of
I have a custom View that is nested inside ScrollView and HorizontalScrollView like this:
I keep finding that if I have nested divs inside each other, and one
I have some nested tables that I want to hide/show upon a click on
I have a nested function to show/hide paragraphs news-ticker-style. The problem is that when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.