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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:50:51+00:00 2026-06-08T17:50:51+00:00

I made my app detect the orientation on the iPad and readjust it’s location

  • 0

I made my app detect the orientation on the iPad and readjust it’s location position accordingly fine so it works good on portrait and landscape.

my problem in the virtual keyboard method that i have it’s not considering the orientation: in portrait once user tap one of the text boxes the method would lift up the view to make room for the keyboard and have the text box visible (not covered) – However when user in landscape and tap a text box the animation would push the view sideways instead of up, as if it’s still in portrait. (same if i hold the iPad upside-down it will push my view frame down instead of up)

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];

    CGRect viewRect = [self.view.window convertRect:self.view.bounds fromView:self.view];
    CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
    CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
    CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) * viewRect.size.height;
    CGFloat heightFraction = numerator / denominator;
    if (heightFraction < 0.0)  {
        heightFraction = 0.0;
    }
    else if (heightFraction > 1.0)   {
        heightFraction = 1.0;
    }

    UIInterfaceOrientation orientation =[[UIApplication sharedApplication] statusBarOrientation];

    if (orientation == UIInterfaceOrientationPortrait ||
        orientation == UIInterfaceOrientationPortraitUpsideDown)   {
        animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
    }
    else    {
        animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
    }

    CGRect viewFrame = self.view.frame;
    viewFrame.origin.y -= animatedDistance;
    // viewFrame.origin.x -= animatedDistance;


    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
    [self.view setFrame:viewFrame];
    [UIView commitAnimations];
}

I also have:

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

How should i change the method to animate it correctly when the device changes orientation?

Thanks

  • 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-08T17:50:53+00:00Added an answer on June 8, 2026 at 5:50 pm

    Detect the orientation and decide which direction to move the view in based on that info.

    if ([UIDevice currentDevice].orientation==UIDeviceOrientationLandscapeLeft)
        viewFrame.origin.x -= animatedDistance;
    if ([UIDevice currentDevice].orientation==UIDeviceOrientationLandscapeRight)
        viewFrame.origin.x += animatedDistance;
    if ([UIDevice currentDevice].orientation==UIDeviceOrientationPortrait)
        viewFrame.origin.y -= animatedDistance;
    if ([UIDevice currentDevice].orientation==UIDeviceOrientationPortraitUpsideDown)
        viewFrame.origin.y += animatedDistance;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made an app which is just working fine. It displays the number of
I made ​​an app for iPhone and iPad with storyboard.Let me know if you
Made an app targeting API8 and it's running fine on all emulator images all
I had some problems in my app I made an app that can detect
I made an app that works on android 2.2 but will be used on
Possible Duplicate: iPad Web App: Detect Virtual Keyboard Using JavaScript in Safari? I'm building
i made an app in architect. My store is this Ext.define('MyApp.store.storeMain', { extend: 'Ext.data.Store',
I made an app using contact sync. I list the following contact info with
A desktop app (made in Delphi) is started by User A. Let's call it
Ive made an app, and published it now. I'm facing a weird problem where

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.