使用最新的xCode和iOS 6构建目标的应用程序是4.3 作为示例,我的第一个视图是8行的tableview。 用户按下第8行并按下第2个视图,该视图也是一个tableView但是有4行。 用户按下第4行并按下标准视图而不是tableView。 sharedManager是我的单例,它指定了方向和检测到的设备(即iPhone或iPad)的tableviews的行高。该应用程序是一个通用的应用程序。
在所有这些视图中,我在viewWillAppear
中有以下内容if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//iPhone Portrait
self.tableView.rowHeight = [sharedManager contactRowHeight];
}
else{
//iPad Portrait
self.tableView.rowHeight = [sharedManager contactRowHeightIpad];
}
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//iPhone Landscape
self.tableView.rowHeight = [sharedManager contactRowHeightLandscape];
}
else{
//iPad Landscape
self.tableView.rowHeight = [sharedManager contactRowHeightLandscape_iPad];
}
}
}
我还会在willRotateToInterfaceOrientation中处理相同的方向更改
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
NSLog(@"willRotateToInterfaceOrientation: %d", toInterfaceOrientation);
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
NSString *iPhoneOrientation;
switch(toInterfaceOrientation) {
case UIInterfaceOrientationLandscapeRight:
iPhoneOrientation = @"UIInterfaceOrientationLandscapeRight";
self.tableView.rowHeight = [sharedManager contactRowHeightLandscape];
break;
case UIInterfaceOrientationLandscapeLeft:
iPhoneOrientation = @"UIInterfaceOrientationLandscapeLeft";
self.tableView.rowHeight = [sharedManager contactRowHeightLandscape];
break;
case UIInterfaceOrientationPortrait:
iPhoneOrientation = @"UIInterfaceOrientationPortrait";
self.tableView.rowHeight = [sharedManager contactRowHeight];
break;
case UIInterfaceOrientationPortraitUpsideDown:
iPhoneOrientation = @"UIInterfaceOrientationPortraitUpsideDown";
self.tableView.rowHeight = [sharedManager contactRowHeight];
break;
default:
iPhoneOrientation = @"Invalid orientation";
}
NSLog(@"willRotateToInterfaceOrientation: %@", iPhoneOrientation);
}
else{
NSString *iPadOrientation;
switch(toInterfaceOrientation) {
case UIInterfaceOrientationLandscapeRight:
iPadOrientation = @"UIInterfaceOrientationLandscapeRight";
self.tableView.rowHeight = [sharedManager contactRowHeightLandscape_iPad];
break;
case UIInterfaceOrientationLandscapeLeft:
iPadOrientation = @"UIInterfaceOrientationLandscapeLeft";
self.tableView.rowHeight = [sharedManager contactRowHeightLandscape_iPad];
break;
case UIInterfaceOrientationPortrait:
iPadOrientation = @"UIInterfaceOrientationPortrait";
self.tableView.rowHeight = [sharedManager contactRowHeightIpad];
break;
case UIInterfaceOrientationPortraitUpsideDown:
iPadOrientation = @"UIInterfaceOrientationPortraitUpsideDown";
self.tableView.rowHeight = [sharedManager contactRowHeightIpad];
break;
default:
iPadOrientation = @"Invalid orientation";
}
NSLog(@"willRotateToInterfaceOrientation: %@", iPadOrientation);
}
}
现在我遇到的问题是从任何一个方向的视图1 - 3开始工作正常但是当我将视图3旋转到横向然后返回到视图2和1时,旋转代码在横向中不起作用即使我为所有元素指定了正确的布局框架,但是从视图1 - 3开始时已经证明了这一点,但显示不正确?
同样有助于确定问题的是第一个视图我隐藏导航栏并在视图2和3中取消隐藏它。不确定这是否有帮助。