【问题标题】:Present two or more ViewControllers at once IOS一次呈现两个或多个 ViewController IOS
【发布时间】:2017-01-11 10:35:41
【问题描述】:

我正在搜索是否有任何方法可以同时呈现两个或多个控制器。

类似导航控制器的东西:https://stackoverflow.com/a/28464115/5790492

但对于模态控制器。 现在我只在第一个控制器中执行presentViewController:animated:false,在第二个控制器中执行另一个presentViewController:animated:true。但得到错误:

Unbalanced calls to begin/end appearance transitions for

我在第二个动画之前看到第一个 ViewController。这不漂亮。如果我使用方法时就完美了:

- (void)presentInController:(UIViewController *)current controllerA:(UIViewController *)controllerA controllerB:(UIViewController *)controllerB;

在屏幕中 - 将切换到带有动画的控制器 B。并且有可能将他解雇给controllerA。

【问题讨论】:

  • 所以不要在屏幕上加载它们,您可以在开始时将它们的框架设置在外面,当它们加载时将它们动画到前面
  • 您是否希望它们同时出现在屏幕上,例如并排?你看过这个developer.apple.com/library/content/featuredarticles/… 吗?

标签: ios objective-c


【解决方案1】:

使用 ContainerView 是我能想到的一种方式。基本上,您拖动 2 个 ContainerView 并且每个都指向您要通过“嵌入”方式显示的 2 个 Viewcontroller(通常您会这样做)。这实际上没有代码,因为它就像从 IB 拖动 ContainerView 对象并拖放到 Storyboard 中的主视图中一样简单。

【讨论】:

  • 答案太模糊(虽然是正确的)。请提供代码片段和更多信息
  • 好的,我添加更多细节。但是 containerview 真的没有任何代码。这是一个拖放项目。
【解决方案2】:

您可以使用 GCD 来避免Unbalanced calls to begin/end appearance transitions for 错误。

//delayInSeconds
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //code to be executed after a specified delay
    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerName"];
    [self presentViewController:vc animated:false completion:nil];
});

根据需要更改 delayInSeconds。

可能是这样的,

  • presentViewController:animated:false
  • 另一个 presentViewController:animated:true with GCD delay

【讨论】:

  • 不平衡调用是在推送实际层次结构(即 viewDidAppear)之前呈现 VC 的产物。您的解决方案不是解决方案,而是临时修复,这是一种不好的做法。
  • 抱歉,我不需要那个延迟,这是主要问题。
  • @NikKov 否则使用委托方法关闭并呈现另一个视图控制器。
猜你喜欢
  • 1970-01-01
  • 2016-10-08
  • 1970-01-01
  • 2020-10-16
  • 2012-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-03
相关资源
最近更新 更多