旋转UIViewController问题

时间:2011-07-01 22:31:27

标签: iphone objective-c cocoa-touch uiviewcontroller uiinterfaceorientation

我有以下代码在UITableViewController的ontop上以水平方向显示UIViewController。

  -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        [self.view addSubview:landscapeChartViewController.view];
    }

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
        toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        if(landscapeChartViewController != nil)
            [landscapeChartViewController.view removeFromSuperview];
    }
}

当手机旋转时,视图不占用整个屏幕。

用户也可以滚动,从而显示UITableViewController的其余部分。我不希望UITableViewController在水平方向存在。

2 个答案:

答案 0 :(得分:1)

尝试[self.view addSubview:landscapeChartViewController.view];

假设您已正确设置框架,这应该是您正在寻找的。

答案 1 :(得分:0)

landscapeChartViewController.view.frame = self.view.bounds,也许?

另请注意,如果您使用的是标签栏控制器,则可能会“在后台”进行方向更改,因此您可能还需要检查-viewWillAppear:中的当前方向。

相关问题