为不同的方向加载不同的.xib

时间:2013-10-31 07:52:39

标签: ios objective-c orientation nib

在我的应用程序中,我想为不同的方向加载不同的.xib,即一个用于纵向,一个用于横向

我搜索了它并找到了解决方案,但它对我不起作用。有人请帮帮我。

这是我的代码: -

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
}

- (void) orientationChanged:(NSNotification *)note {
    UIDevice * device = note.object;
    NSArray *array;
    UIView *mainView;
    if (device.orientation == UIDeviceOrientationPortrait || device.orientation == UIDeviceOrientationPortraitUpsideDown) {
        array = [[NSBundle mainBundle] loadNibNamed:@"NewViewController" owner:self options:nil];
        mainView = [array objectAtIndex:0];
        NSLog(@"Portrait");
    } else {
        array = [[NSBundle mainBundle] loadNibNamed:@"Landscape" owner:self options:nil];
        mainView = [array objectAtIndex:0];
        NSLog(@"Landscape");
    }
}

提前致谢!

0 个答案:

没有答案