【问题标题】:How to load a new view upon orientation change - iOS SDK xcode Interface builder如何在方向更改时加载新视图 - iOS SDK xcode Interface builder
【发布时间】:2011-01-21 00:13:00
【问题描述】:

所以我正在开发这个基于视图的应用程序,并且我有一个应用程序,我想以横向模式启动(还没有完全弄清楚如何做到这一点,因为在 plist 文件中,“初始设备方向”不是根据人们所说的,我假设它曾经是一个选项(我是这个应用程序开发的新手))。

无论如何,当我旋转到纵向时,我想切换到一个全新的视图,当我旋转到纵向倒置时,我还想切换到另一个新视图。到目前为止,我已将 View2Viewcontroller.(h+m) 添加到我的类中,并将 View2.xib 添加到我的资源中。

我有这个代码:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
  if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
     (fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
  {    
    // Load the view controller I want to display in portrait mode...
  }

}

但我不太清楚如何加载视图控制器,甚至不知道该把代码放在哪里。

【问题讨论】:

标签: objective-c xcode ios sdk orientation


【解决方案1】:

我建议您使用 .nibv 文件,最好了解如何通过代码初始化视图。 反正有你需要的。

 [[viewController alloc] initWithNibName:@"viewController" bundle:[NSBundle mainBundle]];

在代码中,您可以通过此代码在没有 nib 文件的情况下执行相同操作

  CGRect rect = [[UIScreen mainScreen] bounds];

//create a full-screen window
    window = [[UIWindow alloc] initWithFrame:rect];

    //create our view controller and add its view to the window
    viewController = [ViewController new];
    [window addSubview:[viewController view]];
    [window makeKeyandVisible];

【讨论】:

    猜你喜欢
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 2013-10-11
    • 1970-01-01
    相关资源
    最近更新 更多