我已经工作了一段时间并且已经发布游戏的引擎现在正在颠倒我的当前项目并立即按照它想象的方式旋转UIView。我用代码创建了接口,这是关于它的样子:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
CGRect screenBounds = [[UIScreen mainScreen] applicationFrame];
CGRect windowBounds = screenBounds;
windowBounds.origin.y = 0.0;
UIWindow* win = [[UIWindow alloc] initWithFrame:windowBounds];
win.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIMyView* view = [[UIMyView alloc] initWithFrame:screenBounds];
UIMyViewController* controller = [[UIMyViewController alloc] init];
controller.view = view;
view.multipleTouchEnabled = true;
view.windowWrapper = this;
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[win addSubview:view];
...
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
{
s32 validOrientations = ((cViewMM*)(self.view)).windowWrapper->GetValidOrientations();
if (toInterfaceOrientation == UIInterfaceOrientationPortrait && (validOrientations & 0x01))
return true;
if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown && (validOrientations & 0x02))
return true;
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft && (validOrientations & 0x04))
return true;
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight && (validOrientations & 0x08))
return true;
return false;
}
仅当我想在UIInterfaceOrientationLandscapeLeft中启动应用程序时才会出现此问题。通过应用程序调试,当我尝试将我的视图内部添加到窗口时,应该多次调用shouldAutorotateToInterfaceOrientation :.首先使用返回false的UIInterfaceOrientationPortrait然后返回true(因为它是有效方向),然后UIInterfaceOrientationLandscapeLeft返回true(因为它是有效的方向,它是设备的当前方向)。
哦,更具体地说,这种情况只发生在iPhone而不是iPad上。他们使用相同的代码来设置此视图。
我做错了什么?
- 编辑 -
好吧我对shouldAutorotateToInterfaceOrientation的执行错了:执行3次要求UIInterfaceOrientationPortrait,2次执行UIInterfaceOrientationLandscapeLeft,然后执行一次UIInterfaceOrientationLandscapeRight,再次执行UIInterfaceOrientationLandscapeLeft。
游戏中心在这一点上正在进行初始化,因为它正在推动一些额外的UI,我认为可能是它,但事实并非如此。
答案 0 :(得分:25)
在Info.plist中检查支持的方向数组以纵向(右侧向上)启动。如果它以任何不同的方向开始,您的应用将以该方向启动。
答案 1 :(得分:2)
我有同样的问题和伤心看到它回答。然后我意识到一个关键的事情,证明这是事情的运作方式:Default.png启动图像也是颠倒的。您无法在应用中执行任何操作来解决此问题。您可以选择正确启动哪种横向模式(左侧或右侧的主页按钮),但您无法使它们同时工作。
答案 2 :(得分:1)
找到了解决方案!
显然,Interface Builder中存在一个错误。如果您只需单击所有方向,然后按所需顺序单击它们,即可正确构建Info.plist。
答案 3 :(得分:0)
在我的情况下,它起作用tgunr说但是我必须从模拟器文件夹中删除整个应用程序,否则,方向的改变不起作用。