0

为应用程序使用最新的 xCode 和 iOS 6 构建目标是 4.3 作为示例,我的第一个视图是 8 行的表格视图。用户按下第 8 行并推送第二个视图,该视图也是一个 tableView,但有 4 行。用户按下第 4 行,它会推送标准视图而不是 tableView。sharedManager 是我的单例,它为任一方向和检测到的设备(即 iPhone 或 iPad)指定表格视图的行高。该应用程序是一个通用应用程序。

在所有这些视图中,我在 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 中取消隐藏它的第一个视图。不确定这是否有帮助。

4

0 回答 0