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 8097851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:53:36+00:00 2026-06-05T21:53:36+00:00

I am trying to change the orientation of a single UIViewController programmatically. The user

  • 0

I am trying to change the orientation of a single UIViewController programmatically. The user should choose in the settings if the view will be portrait or not. The value will be saved in NSUserDefaults and in the specific ViewController the orientation should be changed. So if Portrait is on the interfaceOrientation should be on UIInterfaceorientationUpsideDown……

I used following method but it will only change the orientation when the user will turn the device to landscape/portrait… otherwise nothing will be triggered.

- (BOOL)shouldAutoRotateToInterfactOrientation:(UIInterfaceOrientation)interfaceOrientation

Furthermore i tryied the next one (also with method name “setOrientation“):

[[UIDevice currentDevice] orientation: UIDeviceOrientationPortraitUpsideDown];

But again, nothing happens, there just appear errors because xcode sayes there are no methods with this name.

But ther should be another way to change it programatically…
the first method is also just a method that handles the actionListener after device position but there should be a way to call this actionListener in a direct way….
I just looked inside the UIApplication File but there is no usefull method….

  • 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-06-05T21:53:37+00:00Added an answer on June 5, 2026 at 9:53 pm

    You should use something like this code:

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(rotationChanged:)
                                                 name:@"UIDeviceOrientationDidChangeNotification"
                                               object:nil];
    

    And then, change your view according to the orientation:

    -(void)rotationChanged:(NSNotification *)notification{
        NSInteger orientation = [[UIDevice currentDevice] orientation];
        UIWindow *_window = [[[UIApplication sharedApplication] delegate] window];
        switch (orientation) {
            case 1:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.4];
    
                [_window setTransform:CGAffineTransformMakeRotation (0)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
    
                [UIView commitAnimations];
                break;
            case 2:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.4];
    
                [_window setTransform:CGAffineTransformMakeRotation (M_PI)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
    
                [UIView commitAnimations];
                break;
            case 3:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.4];
    
                [_window setTransform:CGAffineTransformMakeRotation (M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
    
                [UIView commitAnimations];
                break;
            case 4:
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.4];
    
                [_window setTransform:CGAffineTransformMakeRotation (- M_PI / 2)];
                [_window setFrame:CGRectMake(0, 0, 320, 480)];
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
    
                [UIView commitAnimations];
                break;
            default:
                break;
        }
    }
    

    Hope it helps 😛

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

Sidebar

Related Questions

I am trying to change orientation from portrait to landscape for an Android activity.
Am trying to change the button frame according to the orientation change but button
I'm trying to get my app to change layouts when the orientation changes. This
I'm trying to change the body background image whenever orientation changes. This seemed pretty
So I wam trying to forcefully change the device orientation at a part of
I'm trying to set another position for a UIButton when I change the orientation
I have an image view and I am trying to change image of imageview
I'd like my VIEW layout to be adjusted on orientation change. My Manifest is
I have activity with android:configChanges=orientation|keyboardHidden I am trying to change image in ImageView when
I'm having some trouble trying to change my view layout when rotation the device,

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.