0

我编写了一个自定义SplitViewController,它有一个主(自定义UITableView)和一个详细视图控制器,这在 iPad 的横向模式下完美运行。

当方向更改为纵向模式时,我想相应地调整主视图和详细视图的大小和位置,以免看起来不合适。

有人对我如何完成这项工作有任何想法吗?

更新 :

我在我的自定义 SplitViewController 中编写了一个侦听器来寻找方向变化并将其连接到一个看起来像这样的选择器(resetViews :)

-(无效)重置视图{

 if(currentOrientation == UIDeviceOrientationPortrait || currentOrientation ==       UIDeviceOrientationPortraitUpsideDown){

    self.view.frame = CGRectMake(0, 0, 768, 1024);
    masterView.frame = CGRectMake(MASTER_VIEW_PORTRAIT_X,MASTER_VIEW_PORTRAIT_Y,MASTER_VIEW_WIDTH_PORTRAIT,MASTER_VIEW_HEIGHT_PORTAIT);
    detailView.frame = CGRectMake(DETAIL_VIEW_PORTRAIT_X, DETAIL_VIEW_PORTRAIT_Y, DETAIL_VIEW_WIDTH_PORTRAIT, DETAIL_VIEW_HEIGHT_PORTAIT);



}
if(currentOrientation == UIDeviceOrientationLandscapeRight || currentOrientation == UIDeviceOrientationLandscapeLeft){
    NSLog(@"IN Landscape");
    self.view.frame = CGRectMake(0, 0, 1024, 768);
   masterView.frame = CGRectMake(MASTER_VIEW_LANDSCAPE_X,MASTER_VIEW_LANDSCAPE_Y,MASTER_VIEW_WIDTH_LANDSCAPE,MASTER_VIEW_HEIGHT_LANDSCAPE);
    detailView.frame = CGRectMake(DETAIL_VIEW_LANDSCAPE_X,DETAIL_VIEW_LANDSCAPE_Y, DETAIL_VIEW_WIDTH_LANDSCAPE, DETAIL_VIEW_HEIGHT_LANDSCAPE);


}

}

这在设置 viewControllers 的框架时工作正常。

但是 MasterViewController (UITableViewController) 必须在方向改变时动态改变其行的高度 (tableView.rowHeight)。我如何做到这一点而无需为每次方向更改重新加载整个 tableView ([tableView reloadData])?

4

2 回答 2

0

您是否尝试设置 autoresizingMasks 来指定视图所需的调整大小行为?像这样的东西应该与您描述的调整大小相匹配:

splitViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoResizingFlexibleHeight;
masterViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoResizingFlexibleHeight;
detailViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoResizingFlexibleHeight;
于 2012-08-24T14:35:11.710 回答
0

子类 UISplitViewController 并将您的 splitViewController 设置为该类。然后将此方法添加到您的 UISplitViewController 子类中:

-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {
    return NO;
}

如果您想要一种简单的方法来换出详细视图,请添加此方法:

-(void)setDetailControllerTo:(UIViewController *)detailController withNavControllerTitle:(NSString *)title {
[detailController view]; // this line forces the viewDidLoad method to be called

if (title) {
    UINavigationController *navController = [[UINavigationController alloc] init];
    [navController pushViewController:detailController animated:YES];
    detailController.title = title;

    NSArray *viewControllers=@[self.mainController.viewControllers[0],navController];
    self.mainController.viewControllers = viewControllers;
} else {
    NSArray *viewControllers=@[self.mainController.viewControllers[0],detailController];
    self.mainController.viewControllers = viewControllers;
}

}

要调用此方法,请从 tableView:didSelectRowAtIndexPath: 方法中的主视图控制器执行类似的操作

FixedSplitViewController *splitController = (FixedSplitViewController*) self.splitViewController;

CurrentEventViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"CurrentEventViewController"];
// add any setup code here
[splitController setDetailControllerTo:controller withNavControllerTitle:@"Current Event"];
于 2013-11-08T16:20:51.823 回答