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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:26:01+00:00 2026-06-17T09:26:01+00:00

I rotated a view using CGAffineTransformMakeRotation. ( iPhone – allow landscape orientation on just

  • 0

I rotated a view using CGAffineTransformMakeRotation. ( iPhone – allow landscape orientation on just one viewcontroller )

As you can see below, the images have white region in left and right.
I want the image take up the whole space with black background.(at least in one dimension, width or height )

enter image description here

Below is the full code

- (void) viewDidLoad
{
    [super viewDidLoad];

    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.view.backgroundColor = [UIColor blackColor];

    self.imageView.backgroundColor = [UIColor blackColor];
    self.imageView.opaque = NO;
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |
        UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

    [self.imageView setImageWithURL:[NSURL URLWithString:self.jsonAlbumImage.url_image
                                           relativeToURL: [NSURL URLWithString:@URL_BASE]]
                   placeholderImage: [GlobalHelper placeHolderImage]];

    [self.view addSubview: self.imageView];

}

- (void)didRotate:(NSNotification *)notification {
    UIDeviceOrientation orientation = [[notification object] orientation];

    if (orientation == UIDeviceOrientationLandscapeLeft) {
        [self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
    } else if (orientation == UIDeviceOrientationLandscapeRight) {
        [self.view setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
    } else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
        [self.view setTransform:CGAffineTransformMakeRotation(M_PI)];
    } else if (orientation == UIDeviceOrientationPortrait) {
        [self.view setTransform:CGAffineTransformMakeRotation(0.0)];
    }
}

— EDIT —

What worked for me in the end .. don’t know why modification does work.. any explanation would be great!

  UIDeviceOrientation orientation = [[notification object] orientation];

    CGAffineTransform t;
    CGRect rect;
    if (orientation == UIDeviceOrientationLandscapeLeft) {
        t = CGAffineTransformMakeRotation(M_PI / 2.0);
        rect = CGRectMake(0,0,480,320);
    } else if (orientation == UIDeviceOrientationLandscapeRight) {
        t = CGAffineTransformMakeRotation(M_PI / -2.0);
        rect = CGRectMake(0,0,480,320);
    } else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
        t = CGAffineTransformMakeRotation(M_PI);
        rect = CGRectMake(0,0,320,480);
    } else if (orientation == UIDeviceOrientationPortrait) {
        t = CGAffineTransformMakeRotation(0.0);
        rect = CGRectMake(0,0,320,480);
    }
    else
        return; // looks like there are other orientations than the specified 4

    [self.view setTransform:t];
    self.view.bounds = rect;
  • 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-17T09:26:02+00:00Added an answer on June 17, 2026 at 9:26 am

    In - (void)didRotate:(NSNotification *)notification, you need to relayout your views so that they occupy all the space available. You could do something like this:

    - (void)didRotate:(NSNotification *)notification {
      UIDeviceOrientation orientation = [[notification object] orientation];
    
      CGAffineTransform t;
      if (orientation == UIDeviceOrientationLandscapeLeft) {
        t = CGAffineTransformMakeRotation(M_PI / 2.0);
      } else if (orientation == UIDeviceOrientationLandscapeRight) {
        t = CGAffineTransformMakeRotation(M_PI / -2.0);
      } else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
        t = CGAffineTransformMakeRotation(M_PI);
      } else if (orientation == UIDeviceOrientationPortrait) {
        t = CGAffineTransformMakeRotation(0.0);
      }
    
      CGPoint screenCenter = CGPointMake([UIScreen mainScreen].bounds.width/2,[UIScreen mainScreen].bounds.height/2);
      self.view.center = CGPointApplyAffineTransform(screenCenter, t);
      self.view.bounds = CGRectApplyAffineTransform([UIScreen mainScreen].bounds, t);
      [self.view setTransform:t];
    
    }
    

    Where :

    CGRectApplyAffineTransform

    Applies an affine transform to a rectangle.

           CGRect CGRectApplyAffineTransform (
               CGRect rect,
               CGAffineTransform t
             );
    

    Try also removing this line:

    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    

    You don´t need it if you are not going to use autorotation and I fear it might conflict with your own setting the view’s frame. This is just an hypothesis to account for the fact that you are not seeing the view´s frame change.

    EDIT:

    I’d very much like to know what this transform thing does

    well, the transform is doing the rotation.

    rotating is relative to an anchor point which is used as a pivot; what happens is that if the anchor point is not in the middle of the view being rotated, then the view is also translated (imagine a rotation around a vertex).

    So, it is correct to set the bounds to make things even; indeed I was suggesting just that with the lines:

      self.view.center = CGPointApplyAffineTransform(screenCenter, t);
      self.view.bounds = CGRectApplyAffineTransform([UIScreen mainScreen].bounds, t);
    

    but possibly the idea of applying the same transform to both the center and the bounds was not blessed. (that is also why I asked for some traces, to see what was happening 🙂

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

Sidebar

Related Questions

I use... -(void)didRotateFromInterfaceOrientation: ... to adapt a view that has been rotated to landscape.
How can I manually rotate a view using the autoresizingMasks, as if the user
How do you manually rotate a view 180 degrees using CGAffineTransformMakeRotation?
I have an UIImageView which can be rotated, panned and scaled with gesture recognisers.
I'm trying to center a rotated image into a destination buffer using GDI+. The
I'm using following code to animate a view. It basically rotates the view by
I have this view and I do some rotation transformation to it using something
Is there a way to load a portrait only view controller in portrait orientation
I have set the background for a given view using the following code, however,
I am rotating an NSView using: setFrameRotation: Which rotates the view around its bottom

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.