简体   繁体   English

iPhone视图不会旋转

[英]iPhone view won't rotate

This is a continuation from a previous question that I asked: iPhone View Strategy 这是我之前提出的问题的延续: 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: 我已经在我所有的视图控制器中实现了shouldAutorotateToInterfaceOrientation方法,如下所示:

// 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. 假设您的gameViewController已在代码中的其他地方初始化。 Not sure if that is what you are looking for but it may work. 不知道这是您要找的东西,但它可能有效。

你那里有UITabBarController吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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