代码之家  ›  专栏  ›  技术社区  ›  jonathanpeppers

iPhone/iPad-切换视图导致定位问题

  •  0
  • jonathanpeppers  · 技术社区  · 14 年前

    我正在开发一个通用的iPhone/iPad应用程序。我使用MonoTouch,但是我可以在Obj-C中获取答案(我应该能够破译它,MonoTouch的UIKit在很大程度上是1比1)。

    基本上我的应用程序有两个视图:“登录”视图和“登录”视图。

    在应用程序启动时,“我的登录”视图是主窗口的唯一子视图。登录后,我在登录视图上调用RemoveFromSuperview并UIWindow.AddSubView添加登录视图。所有这些工作都很好,方向也工作b/c I响应ShouldAutorotatePointerFaceOrientation。

    在UIWindow中切换视图的正确方法是什么?我觉得方向应该自动工作,所以我做错了。

    更新:

    下面是一段代码片段(用C#,但你明白了):

    _loginController.View.RemoveFromSuperView();
    _window.AddSubView(_loggedInController.View);
    

    要执行相反的操作:

    _loggedInController.View.RemoveFromSuperView();
    _window.AddSubView(_loginController.View);
    

    很简单吧?

    我做了一个简单的重新编程——甚至包括一个UISplitViewController,它工作得很好。

    3 回复  |  直到 14 年前
        1
  •  0
  •   gabaum10    14 年前

    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中存在一个错误,如果在执行ApplicationIDFinishLaunching方法后显示方向,则不会检查方向。

        2
  •  0
  •   gabaum10    14 年前

    好吧,我知道,我有一个类似的应用程序,但只是处理问题的方式不同。

    我在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];
    

    给这样的东西一次机会,看看效果如何。:)

        3
  •  0
  •   jonathanpeppers    14 年前

    在我的新项目中,这个问题随机地开始发生(不确定我改变了什么使它发生)。所以在我的UI布局中一定有什么东西导致了它。

    我听取了一位评论者的建议,并查看了模态视图。

    以下工作很好:

    • 使SplitViewController成为顶级视图
    • 注销功能是:_loggedInController.PresentModalViewController当前(\u loginController,true);
    • 登录功能是:_loggedInController.DismissModalViewController已激活(正确);

    现在没有奇怪的定向问题发生。

    这也给了mes一个很好的滑动转换的好处,而无需添加任何代码。