Iphone 旋转设备时如何更换新笔尖?

Iphone 旋转设备时如何更换新笔尖?,iphone,objective-c,Iphone,Objective C,我有一个helloController,它是一个UIViewController,如果我旋转设备,我希望它将其更改为加载一个新的nib“helloHorizontal.xib”,我该怎么办?谢谢。您可以这样做,(我手头没有xcode,所以这段代码可能不完全准确) 我相信这是正确的方法。我在我的应用程序中使用它,它工作得非常完美 启用的触发器将旋转,而不应旋转(等待旋转动画即将启动) 对横向/纵向文件使用Apple命名约定(如果希望Apple自动加载横向版本,则Default.png为Defaul

我有一个helloController,它是一个UIViewController,如果我旋转设备,我希望它将其更改为加载一个新的nib“helloHorizontal.xib”,我该怎么办?谢谢。

您可以这样做,(我手头没有xcode,所以这段代码可能不完全准确)


我相信这是正确的方法。我在我的应用程序中使用它,它工作得非常完美

  • 启用的触发器将旋转,而不应旋转(等待旋转动画即将启动)
  • 对横向/纵向文件使用Apple命名约定(如果希望Apple自动加载横向版本,则Default.png为Default-landscape.png)
  • 重新加载新的笔尖
  • 这将重置self.view-这将自动更新显示
  • 然后调用viewDidLoad(如果您手动重新加载NIB,苹果将不会为您调用此选项)
  • (NB stackoverflow.com需要这句话-代码格式化程序中有一个bug)


    但是面向肖像的视图仍然会在堆栈上,不是吗?因此,后退按钮将指向错误的对象。好的方面是,当视图旋转时,您可以隐藏导航栏,或者已经创建视图,并在旋转时淡入淡出另一个视图。
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)){
    WhatYourNewViewClassISCAlled* newView = [[WhatYourNewViewClassISCAlled alloc] initWithNibName:@"NIBNAME" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:newView animated:YES];
    }
    
    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) )
        {
            [[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@-landscape", NSStringFromClass([self class])] owner:self options:nil];
    
            [self viewDidLoad];
        }
        else
        {
            [[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@", NSStringFromClass([self class])] owner:self options:nil];
    
            [self viewDidLoad];
        }
    }