这就是我所拥有的。我的问题是,为了改变后者的滚动视图大小,我不想在有用的时间将 tableview 的框架高度从 tableview 控制器返回到 UserProfileViewController。我也觉得我在某种程度上是在倒退,所以任何建议都非常受欢迎。
此视图有两个部分:上部和下部。父视图是滚动视图。我想要实现的是在上部有一种标签栏,它将控制 waht 将出现在下部。
当按下左上角按钮以显示另一个视图时,上部有一个翻转动画。实现这一点的方法是拥有 2 个视图:虚拟视图和后视图。虚拟视图具有小时候的正视图。前视图是包含所有按钮的视图。这个动画的代码是这样实现的:
- (IBAction)infoButtonPressed:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.hoverView cache:YES];
if ([self.headerView superview]) {
[self.headerView removeFromSuperview];
[self.hoverView addSubview:self.backOfHeaderView];
[self.infoButton removeFromSuperview];
[self.backOfHeaderView addSubview:self.infoButton];
} else {
[self.backOfHeaderView removeFromSuperview];
[self.hoverView addSubview:self.headerView];
[self.infoButton removeFromSuperview];
[self.headerView addSubview:self.infoButton];
}
[UIView commitAnimations];
}
下部由充当占位符的容器视图制成。当按下按钮时,容器视图中会显示不同的视图控制器。
每个视图控制器都有自己的容器视图。当控制器加载时,该视图控制器(tableview)的特定视图被添加到它的容器视图中。它还确保如果 tableview 已经添加到容器视图中,它将被删除。所有这些都是在每个特定的视图控制器中完成的。
在 User Profile 视图的视图控制器中,有一个容器视图的实例和一个 UIViewController,它也充当占位符(从现在开始命名为 currentViewController)。当按下特定按钮时,它会检查我们想要显示的视图控制器的实例是否已经存在。如果不是,它将创建一个并将其 tableview 的框架设置为容器视图的边界。之后,它将从父视图控制器中删除 currentViewController 的视图,并从父视图控制器中删除 currentViewController 本身,以确保如果有分配给这些的东西,它们将不存在。然后它将所需的视图控制器分配给 currentViewController。它还分配所需的视图控制器' s containerView 实例到父视图控制器(用户配置文件视图控制器)中的容器视图。最后,它会将所需的视图控制器作为子视图添加到主视图控制器(用户配置文件视图控制器)中,并将所需的视图控制器的视图添加到主视图控制器的 containerView 中。这是其中一个按钮的代码:
//Check if there is an instance of the viewcontroller we want to display. If not make one and set it's tableview frame to the container's view bounds
if(!_userWallViewController) {
self.userWallViewController = [[WallViewController alloc] init];
// self.userWallViewController.activityFeedTableView.frame = self.containerView.bounds;
}
[self.userWallViewController.containerView addSubview:self.userWallViewController.activityFeedTableView];
//If the currentviewcontroller adn it's view are already added to the hierarchy remove them
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
//Add the desired viewcontroller to the currentviewcontroller
self.currentViewController = self.userWallViewController;
//Pass the data needed for the desired viewcontroller to it's instances
self.userWallViewController.searchURLString = [NSString stringWithFormat:@"event/user/%@/", self.userID];
self.userWallViewController.sendCommentURLString = [NSString stringWithFormat:@"event/message/%@", self.userID];
self.userWallViewController.totalCellHeight = ^(float totalCellHeight){
self.userWallViewController.numberOfCells = ^(float numberOfCells){
NSLog(@"The total number of cells: %f", numberOfCells);
NSLog(@"The total cell height: %f", totalCellHeight);
self.scrollView.contentSize = CGSizeMake(320.0, totalCellHeight + 172.0 + 33.0);
CGRect newFrame = self.userWallViewController.containerView.frame;
newFrame.size.height = totalCellHeight + 33.0;
self.userWallViewController.containerView.frame = newFrame;
NSLog(@"Container view: %f", self.containerView.frame.size.height);
NSLog(@"Scroll view: %f",self.scrollView.contentSize.height );
};
};
//Add this containerview to the desired viewcontroller's containerView
self.userWallViewController.containerView = self.containerView;
//Add the needed viewcontroller and view to the parent viewcontroller and the containerview
[self addChildViewController:self.userWallViewController];
[self.containerView addSubview:self.userWallViewController.view];
[self performSelector:@selector(changeScrollView) withObject:self afterDelay:0.5];
//CLEAN UP THE CONTAINER VIEW BY REMOVING THE PREVIOUS ADDED TABLE VIEWS
[self.userFansViewController.userSimpleTableView removeFromSuperview];
[self.fanOfViewController.userSimpleTableView removeFromSuperview];
[self.userPublishedMovellaListViewController.gridView removeFromSuperview];
[self.userPublishedMovellaListViewController removeFromParentViewController];
self.userPublishedMovellaListViewController = nil;
}