简体   繁体   中英

iPhone view won't rotate

This is a continuation from a previous question that I asked: iPhone View Strategy

I am now using the following method to switch between views:

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[window setRootViewController:[self gameViewController]];
[[[self gameViewController] view] becomeFirstResponder];

The problem I am having is that none of my views rotate properly (the status bar rotates but nothing else). The initial view is fine but any views that I navigate to using the above method have the problem with rotation.

I have implemented the shouldAutorotateToInterfaceOrientation method in all of my view controllers as follows:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES to allow autorotation
    return YES;
}

This has become a bit of a sticking point for me. Any ideas?

Thanks, Alan

It might be how you are displaying your views. I was having this problem with a popover that was displaying a modal window. Still not sure what was causing the problem, think it was an apple bug. Why don't you try doing something like this:

[window addSubview:gameViewController.view];
[window makeKeyAndVisible];

This is assuming that your gameViewController is initialized somewhere else in your code. Not sure if that is what you are looking for but it may work.

你那里有UITabBarController吗?

shouldAutorotateToInterfaceOrientation方法应该放在视图的当前视图控制器中,而不是UIViews本身。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM