我需要在解除子视图控制器后保留子视图控制器,以便在需要时将其移回,而无需在子视图控制器中进行额外处理。我尝试使用以下链接实现它:
这些链接(以及类似的其他链接)确实起到了引入子视图控制器或将其关闭但不是“保留它”的目的。请在下面找到我的代码:
/* Adding a child view controller */
self.detailsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsViewController"];
self.detailsViewController.name = @"DetailsText";
// data to do "processing in viewDidLoad of child"
self.detailsViewController.someOtherDataForProcessing = someOtherDataForProcessing;
self.detailsViewController.delegate = self;
[self addChildViewController:self.detailsViewController];
self.detailsViewController.view.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 200);
[self.view addSubview:self.detailsViewController.view];
/* Bringing the child up on swipe gesture */
[UIView animateWithDuration:0.5 animations:^{
self.detailsViewController.view.frame = CGRectMake(0, 100, self.view.frame.size.width, 200);
} completion:^(BOOL finished) {
[self.detailsViewController didMoveToParentViewController:self];
}];
/* Moving child down when back pressed on child */
[UIView animateWithDuration:0.5 animations:^{
[self.detailsViewController willMoveToParentViewController:nil];
self.detailsViewController.view.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 200);
} completion:^(BOOL finished) {
[self.detailsViewController.view removeFromSuperview];
[self.detailsViewController removeFromParentViewController];
}];
如果我需要“再次在父母身上滑动”带子控制器,我必须再次完成整个过程。我需要做的只是做“让孩子在滑动手势上出现”过程而不是再次实例化,因为实例化会在子控制器中处理数据(耗时)。
我是 iOS 应用程序编程的菜鸟,所以如果这是一个明显的问题,请多多包涵。