我使用下面的代碼來實現它,但它不起作用。請給我一些建議。非常感謝。在iOS中定位時加載另一個.xib
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
orientationChanged()函數:
- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}
adjustViewsForOrientation()函數:
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(@"load portrait view");
[[NSBundle mainBundle] loadNibNamed:@"DashBoardViewController" owner:self options:nil];
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
NSLog(@"load landscapeview");
[[NSBundle mainBundle] loadNibNamed:@"DashBoardLandscapeView" owner:self options:nil];
}
}
運行時總是顯示DashBoardViewController.xib。在lanscape中,它仍然顯示DashBoardViewController.xib。我不知道爲什麼。
非常感謝,它工作正常:) – user3125692
真棒,很高興我可以幫助! – adeiji