我正在开发一款通用的iPhone / iPad应用程序。我正在使用MonoTouch,但我可以在Obj-C中找到答案(我应该能够解读它,MonoTouch的UIKit大部分都是1比1)。
基本上我的应用有2个视图:“登录”视图和“登录”视图。
在应用启动时,我的登录视图是我的主UIWindow的唯一子视图。登录后,我在登录视图和UIWindow.AddSubView上调用RemoveFromSuperview来添加登录视图。所有这些都很有效,并且方向也可以b / c我响应ShouldAutorotateToInterfaceOrientation。
所有直到您退出,方向开始全部抬起。在方向上,应用程序定位状态栏,但保持我的视图不变。最重要的是,在iPad上我的UISplitView非常奇怪,我的主视图以一种方式定向,而细节视图另一种方式。
在UIWindow中切换视图的正确方法是什么?我觉得这些方向应该自动运作,因此我做错了。
更新:
这是一个代码片段(在C#中,但你明白了):
_loginController.View.RemoveFromSuperView();
_window.AddSubView(_loggedInController.View);
要做相反的事情:
_loggedInController.View.RemoveFromSuperView();
_window.AddSubView(_loginController.View);
相当直白,对吧?
更新2:
我做了一个简单的复制 - 甚至包括一个UISplitViewController,它工作得很好。
我的应用中必定存在某些特定的行为导致这种奇怪的行为。
答案 0 :(得分:0)
如果我理解正确,您可以在加载新视图之前检查视图方向。我想我做了几乎相同的事情。尝试做这样的事情:
CGRect frame = [[UIScreen mainScreen] applicationFrame];
switch(splitViewController.interfaceOrientation){
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
[splitViewController.view setFrame:frame];
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
[splitViewController.view setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.height, frame.size.width)];
break;
}
基本上获取当前的应用程序框架并手动定位它。 splitViewController中存在一个错误,如果在执行applicationDidFinishLaunching方法后显示方向,则不会检查方向。
答案 1 :(得分:0)
好的,我知道,我有一个类似的应用程序,但只是以不同的方式处理问题。
我在appDidFinishLaunching方法中创建并初始化了splitViewController并将其传递到我的登录屏幕。
theLoginScreen = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]];
theLoginScreen.splitViewController = splitViewController;
theLoginScreen.detailViewController = detailViewController;
theLoginScreen.rootViewController = rootViewController;
theLoginScreen.appDelegate = self;
[window addSubview:theLoginScreen.view];
从这里我做了登录的东西,然后做了类似的事情:
[self.view removeFromSuperview];
CGRect frame = [[UIScreen mainScreen] applicationFrame];
switch(splitViewController.interfaceOrientation){
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
[splitViewController.view setFrame:frame];
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
[splitViewController.view setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.height, frame.size.width)];
break;
}
[appDelegate.window addSubview:splitViewController.view];
给出像这样的东西,看看是否有效。 :)
答案 2 :(得分:0)
在我的新项目中,问题随机开始发生(不确定我做了什么改变才能实现)。因此,我的UI布局中必定会有一些内容导致它。
我从评论者那里得到了一个建议,并看了一下模态视图。
以下效果很好:
现在没有发生奇怪的方向问题。
这也为mes提供了良好的滑动过渡的好处,而无需添加任何代码来实现它。