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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:21:29+00:00 2026-05-17T21:21:29+00:00

In my iPhone app I need to detect the current orientation and I have

  • 0

In my iPhone app I need to detect the current orientation and I have to determine if I’m in portrait or landscape. I use this code:

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
     NSLog(@"portrait");
     ...
} else {
     NSLog(@"landscape");
     ...
}

Everything is ok when my iPhone is in my hand.
But when i put it on the table and i run the application, the content is displayed on the screen in portrait mode and my code goes to else and NSLog prints landscape.

Is my test incomplete ? How to prevent this case ?

EDIT : the test is performed in my controller viewDidLoad method and my application handle rotation.

  • 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-17T21:21:30+00:00Added an answer on May 17, 2026 at 9:21 pm

    UIDevice.orientation is of type UIDeviceOrientation, which is a superset of UIInterfaceOrientation. You are probably getting the value UIDeviceOrientationFaceUp.

    This underscores that yes, your test is incomplete. You should write something like this:

    UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
         NSLog(@"portrait");
         ...
    } else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
         NSLog(@"landscape");
         ...
    } else {
         NSLog(@"WTF? %d", orientation);
         assert(false);
    }
    

    Then, you’ll know if you if you’ve missed something.

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

Sidebar

Related Questions

i use sqlite database on my iphone app and i need to update this
In my iPhone app, I have this in my .h file #define ORIENTATION_IS_PORTRAIT UIDeviceOrientationIsPortrait([[UIDevice
I need to have a few buttons in my iPhone app (which may be
I m new to iphone app development and i need some help. I have
I have an iPhone app and I need it to open up Safari in
I have been making an iPhone App where I need to identify and decompose
I have an XIB-less Enterprise MonoTouch iPhone app and I need to distribute it
I need to develop a Iphone 2D app for school project. I don't have
My iPhone app is all in portrait mode at the moment. But I need
I have built an iPhone app that I need to test on an actual

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.