0

在我的应用程序中,我想为不同的方向加载不同的 .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");
    }
}

提前致谢!

4

0 回答 0