【发布时间】:2011-12-09 12:32:48
【问题描述】:
我已经开发了一段时间并已发布游戏的引擎现在正在颠倒启动我当前的项目,并立即按照预期的方式旋转 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 的 UIInterfaceOrientationLandscapeRight(因为它是有效的方向),然后是也返回 true 的 UIInterfaceOrientationLandscapeLeft(因为它是有效的方向并且它是设备的当前方向)。
哦,更具体地说,这只发生在 iPhone 上,而不是 iPad 上。他们使用相同的代码来设置此视图。
我做错了什么?
-- 编辑--
好的,我对 shouldAutorotateToInterfaceOrientation 的执行有误:它执行了 3 次,请求 UIInterfaceOrientationPortrait,2 次请求 UIInterfaceOrientationLandscapeLeft,然后一次请求 UIInterfaceOrientationLandscapeRight,再次请求 UIInterfaceOrientationLandscapeLeft。
GameCenter 已经在此时初始化,因为它正在推送一些额外的 UI,我认为可能是它,但事实并非如此。
【问题讨论】:
-
'我做错了什么?'不是站在你的头上? =]
-
如果有帮助我会去做的。
标签: iphone ios orientation