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

时间:2010-08-18 08:02:49

标签: iphone objective-c

我有一个helloController,它是一个UIViewController,如果我旋转设备,我希望它改变它来加载一个新的笔尖“helloHorizo​​ntal.xib”,我该怎么办?谢谢。

2 个答案:

答案 0 :(得分:1)

你可以这样,(我没有方便的xcode所以这段代码可能不完全准确)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)){
WhatYourNewViewClassISCAlled* newView = [[WhatYourNewViewClassISCAlled alloc] initWithNibName:@"NIBNAME" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];
}

答案 1 :(得分:1)

我相信这是正确的方法。我在我的应用程序中使用它并且它完美地运行

  1. 在WILL旋转时触发,不应该旋转(等待旋转动画即将开始)
  2. 对横向/纵向文件使用Apple命名约定(如果您希望Apple自动加载横向版本,则Default.png为Default-landscape.png)
  3. 重新加载新的NIB
  4. 重置self.view - 这将自动更新显示
  5. 然后调用viewDidLoad(如果您手动重新加载NIB,Apple将不会为您调用此方法)
  6. (NB stackoverflow.com在这里要求这句话 - 代码格式化程序中存在错误)

    -(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];
        }
    }