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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:31:19+00:00 2026-05-23T23:31:19+00:00

Background: App has a shake to go home feature. Home view Only supports portrait.

  • 0

Background: App has a shake to go home feature. Home view Only supports portrait.
If you shake a bit harder than usual, the view that you are on starts to rotate (which is fine) , but then it detects a shake and does a popViewControlller to the home view. When it does this it loads the navigation controller just fine, but the view under (the home content) gets loaded behind the bar and is stretched up (it’s basically loading underneath the navigation bar, so it gets stretched up)

The back button handles this just fine from landscape to portrait (since its not mid transitions)

How should I go about handling this orientation change (from the shake) so I can pop back into the root view controller, without the view loading under the navigation bar?

Edit:What’s happening is the content thinks that it has the entire view to load, so it stretches itself to take the entire screen, not realizing theres a navigationbar above it. I can tell since the images loading are stretched out

added a bounty of 50.

Edit Here’s How I’m detecting Shakes and Popping

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{

    if ( event.subtype == UIEventSubtypeMotionShake )
    {

            UINavigationController *navController = self.navigationController;

            [[self retain] autorelease];
            HomeViewController *home = [[HomeViewController alloc]init];
            [navController popViewControllerAnimated:YES];

            home.title =@"Home View Controller";
            [home release];     
        }

    if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
        [super motionEnded:motion withEvent:event];
}

Here’s my App Delegate:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    navController = [[UINavigationController alloc]init];
    [self.window addSubview:navController.view];

    HomeViewController *home = [[HomeViewController alloc]init];
    [[self home] setFrame:[[UIScreen mainScreen] applicationFrame]];

I’ll include a mockup here.

Normal View:

Normal View

Stretched View After a Shake/Pop:

Streched

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}
  • 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-23T23:31:20+00:00Added an answer on May 23, 2026 at 11:31 pm

    I’m a bit puzzled by your code so I’d really suggest starting from the beginning. As Lukya mentioned, there’s no reason to recreate the HomeViewController. I’m also baffled by the “[[self retain] autorelease];” bit. That shouldn’t be necessary unless you’re doing something incorrectly elsewhere.

    So I would start with this… In application:didFinishLaunchingWithOptions: do something like this:

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
        {
            HomeViewController *home = [[[HomeViewController alloc] init] autorelease];
            UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:home] autorelease];
            [self.window addSubview:navController.view];
        }
    

    The window will retain a your nav controller and the nav controller will retain your HomeViewController.

    Then in motionEnded:withEvent: do something like:

        - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
        {
            if (event.subtype == UIEventSubtypeMotionShake)
            {
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
    

    That should be it.

    If that does not work then can you give any other info? For example, does HomeViewController implement (and return YES) in shouldAutorotateToInterfaceOrientation:? If so, can you return no so it doesn’t rotate since your first line says “Home view Only supports portrait”?

    Edit: An example of willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation: as well.

    In the header for whatever controller you’re detecting shakes in add a boolean:

    
        BOOL isRotating;
    
    

    In your implementation file add the two UIViewController methods we want to override — something like:

    
        - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
            [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
            isRotating = YES;
        }
    
        - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
            [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
            isRotating = NO;
        }
    

    Now, do something like this for your event handler:

        - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
        {
            if (event.subtype == UIEventSubtypeMotionShake && !isRotating)
            {
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I detect that an app has just returned from background mode? I
Background I'm writing an part of my app that has no UI. It sits
My app has a background thread that periodically retrieves data from an external source,
I'm finding that after my app has been in the background for a while,
I've got an Android app which has a periodic background Service. I want this
My app have a background image that fills the screen. I'd like to display
Every screen of my app has a common tint. Its not a background. Its
Details The app has a background service running when the app is started. In
I'm creating an app that has a foreground app (of course) and both a
i want the spash screen to only show when the app has been compltely

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.