Search code examples
iosipadorientationuiinterfaceorientation

How to restrict rotations of view based on selected tab (iPad)?


I have an app with several different tabs. The first of these tabs should only allow portrait rotations, however I want the rest of the tabs to be able to rotate freely. Is this even possible? If so how can I achieve this effect?


Solution

  • In the view controllers' .m file for the respective tabs you can set interface orientation as per your requirement to portrait or landscape.

    Here is the the snippet of code block in the view controllers' .m file

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
        } else {
            return YES;
        }
    }