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

The Archive Base Latest Questions

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

Question 1: How do I get the correct size of a UIView? I am

  • 0

Question 1:

How do I get the correct size of a UIView?

I am creating a CGRect to show some images using tiled layers.
When I’m creating the CGRect, I basically need it to be the exact same size as that of my UIView. This turned out to be quite hard..
When I NSLog() out my mainView.bounds.size.width or my mainView.frame.size.width they are always wrong when in landscape! They always log out the values as if it was in portrait, even though I can see the actual view being wider. And reversing them will also be wrong.
It’s not good enough set the width to be the height and vice versa when in landscape, I need the right values.

The only way I’ve been able to make it look right is to manually put in 1024 for width when in Landscape, and this doesn’t always work either, because:

Question 2:

What is the correct way to check if the device is in landscape or not?

I’ve been using

if([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight)

but this doesn’t always work. If I hold my device in landscape mode when launching, it is correct, but if I make it landscape, then lay the iPad flat down leaving the dashboard as landscape and THEN launch it, then the landscape-splash shows up, but that code think it’s in portrait.
That code doesn’t work at all for iPad simulator either..

EDIT

For some reason, when I decided to add support for landscape orientation, it wasn’t enough to just check the landscape-orientations in the summary-page of the target, I had to actually sub-class my TabBarController and physically tell it to rotate with

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

I shouldn’t have to do this.. right? If I create an empty project like that, it doesn’t need it.. I don’t know why.

  • 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:28:33+00:00Added an answer on June 17, 2026 at 9:28 am

    Question 1:
    Yup, that’s right. 🙂

    Question 2:
    I just got home and checked my own code. I use:

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    

    to check the orientation of the current interface. Then, you can use something like:

    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
        // Do something
    } else if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
        // Do something else
    }
    

    HOWEVER You really should not need to do this if you properly handle rotation events.

    Here is my typical way of dealing with rotation when I need to adjust UI element positions in code based on orientation:

    #pragma mark - View rotation methods
    
    // Maintain pre-iOS 6 support:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    
    // Make sure that our subviews get moved on launch:
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
        [self moveSubviewsToOrientation:orientation duration:0.0];
    }
    
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    
        [self moveSubviewsToOrientation:toInterfaceOrientation duration:duration];
    }
    
    // Animate the movements
    - (void)moveSubviewsToOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
    {
        [UIView animateWithDuration:duration
                         animations:^{
                             [self.tableView reloadData];
                             if (UIInterfaceOrientationIsPortrait(orientation))
                             {
                                 [self moveSubviewsToPortrait];
                             }
                             else
                             {
                                 [self moveSubviewsToLandscape];
                             }
                         }
                         completion:NULL];
    }
    
    - (void)moveSubviewsToPortrait
    {
        // Set the frames/etc for portrait presentation
        self.logoImageView.frame = CGRectMake(229.0, 21.0, 309.0, 55.0);
    }
    
    - (void)moveSubviewsToLandscape
    {
        // Set the frames/etc for landscape presentation
        self.logoImageView.frame = CGRectMake(88.0, 21.0, 309.0, 55.0);
    }
    

    I also put moveSubviewsToOrientation in viewWillAppear to have it rotate

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

Sidebar

Related Questions

This is a simple question: Is this a correct way to get an integer
I'm using Alberto Santini's solution to this question to get a spiral grid reference
I am trying to get a file size of remote file compiler-latest.zip (googlecode.com) using
I was looking for an anwer to question Get next N elements from enumerable
HTML Javascript question to get the selected value of a input-select I can use
From my question at Get Foreign Key Value , I managed to get the
I have a route defined like this: GET /question/:q_id controllers.Questions.viewQuestion(q_id: Long) Then in my
Question: I can get the SQL Server database language by querying: SELECT @@language And
QUESTION: how to get at the star above the numbers My FIDDLE currently does
Very basic question - how to get one value from a generator in Python?

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.