【问题标题】:two views orientation problem两个视图方向问题
【发布时间】:2010-08-06 10:11:58
【问题描述】:

我是 iphone 开发新手..

我正在创建一个小型应用程序,其中两个视图控制器类似

  1. 登录控制器
  2. 更新控制器

对于应用方向,我为每个控制器创建了两个视图,例如 为了 第一个控制器是“landscapeLoginView”和“portraitLoginView” & 其次是 'landscapeUpdateView' 和 'portraitUpdateView'

我在 MainControllerDelegate 文件中定义了 'isLogin' 变量,

定位代码如下,

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

TestAppDelegate *testDelegate = (TestAppDelegate *)[[UIApplication sharedApplication] delegate];

if(testDelegate.isLogin) {
    UpdateController *updateController = [[UpdateController alloc] initWithNibName:@"UpdateController" bundle:nil];
    [self.view addSubview:updateController.view];
    [updateController release];
    return YES;
} else 
{
    if(UIInterfaceOrientationIsPortrait(interfaceOrientation))
    {
        self.view = self.portrait;
    }
    else if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
    {
        self.view = self.landscape;
    }
    return YES;
} 

}

这将在单击“登录”按钮后加载尊重的方向。 'LoginController' 的一切工作正常,如按钮事件和所有。

但是, 当我在“UpdateConroller”上输入并通过单击“更新”按钮从 TextView 更新文本时,它会更新为“PortraitView”而不是“LandscapeView”。

在 Interface Builder 中,我将“PortraitView”设置为“view”。

我怎样才能为“LandscapeView”实现相同的功能?我做得对吗?

【问题讨论】:

    标签: iphone


    【解决方案1】:

    你真的应该使用 UIView autoresizingMask 的能力...所以你将只有一个 UIViewController 用于纵向和横向模式

    它会更快,使用起来也不会那么麻烦。

    【讨论】:

      【解决方案2】:

      这不是执行视图更改的正确位置。此方法将仅查询您的应用程序是否可以支持某些方向。请改用willRotateToInterfaceOrientation:duration: 更改您的视图。还要确保在您的 Nib 中为纵向和横向视图创建并连接插座。

      【讨论】:

        【解决方案3】:

        我通过仅使用一个视图并根据方向重新定位所有控件来解决此问题。

        【讨论】:

          【解决方案4】:

          我自己对 iPhone 开发还很陌生,但据我了解,shouldAutorotateToInterfaceOrientation 不是处理轮换的正确位置。它用于定义您的应用可以处理哪些方向。

          为了处理方向问题,您应该在willRotateToInterfaceOrientation:duration 中实现您的旋转功能。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2014-06-14
            • 1970-01-01
            • 1970-01-01
            • 2011-09-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多