Andrew
Andrew

Reputation: 16051

App doesn't rotate on iPhone Simulator

I'm wanting to test out my app with the iPhone 5 resolution, so I'm using the simulator. My app has Portrait and 2 landscape orientations in Supported Device Orientations, and the viewControllers which allow rotation have shouldAutorotateToInterfaceOrientation set to YES. Yet when I rotate the device in the simulator, it doesn't rotate as it does on the device. Right now i'm just using the standard iPhone 4 simulator.

Edit: This is the code I have for setting my VC.

UIViewController *vc = [[UIViewController alloc] init];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    [self.window addSubview:self.navigationController.view];

self.loadingWood = [[UIImageView alloc] init];
[vc.view addSubview:self.loadingWood];

And then shortly after:

self.timeline = [[JTimelineViewController alloc] init];
[self.navigationController setViewControllers:[NSArray arrayWithObject:self.timeline]];

This is necessary for visuals when the app starts up.

EDIT 2:

I now have this working. The problem I now face is that despite one of my viewControllers stating this, it still rotates upon any rotation on the iPhone Simulator:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

EDIT 3: My phone is running iOS5. The simulator is running iOS6. This is a possible reason. Removing Landscape Left and Landscape Right as supported orientations means no simulator rotation at all, but my iOS5 iPhone 4 continues to rotate as normal.

Upvotes: 1

Views: 2068

Answers (2)

Simon Germain
Simon Germain

Reputation: 6844

I had to deal with something similar in the past. What's going in is that only the main view controller of the application receives the rotation notifications and delegate calls. There are some exceptions, like the UINavigationController, that passes down those events to their current view controller.

So, for example, if your AppDelegate class loads a view controller and that view controller pushes a second view controller, that second view controller will not receive the rotation notifications.

I recommend you use a UINavigationController to push your UIViewControllers onto the display, since UINavigationController passes down the rotation delegate calls and notifications.

EDIT

In Xcode's preference, under the Download tab, you have the option of downloading previous simulators, iOS 5 and iOS 5.1. Download those and set your target iOS version to 5.0 (or 5.1) and select the correct simulator from the device list. See if you get the same problem as with the iOS 6 simulator. If you get that, than there's definitely a difference between iOS 5 and iOS 6's way of handling UINavs.

Also, using the difference between setViewControllers and pushViewController is that pushViewController adds the view controller as a child of the parent view controller, which makes it respond to the delegate calls, including rotation. Since iOS 5, every UIViewController now has a method called addChildViewController that gives that functionality to the UIViewController class.

Upvotes: 1

Mike M
Mike M

Reputation: 4436

Make sure that you're setting the root view controller, as in:

    self.window.rootViewController = self.navigationController;

Upvotes: 1

Related Questions