【问题标题】:iOS 7 UITableView didSelectRowAtIndexPath pushViewController programmatically, Animation issueiOS 7 UITableView didSelectRowAtIndexPath pushViewController 以编程方式,动画问题
【发布时间】:2013-10-15 20:17:39
【问题描述】:

编辑:我找到了自己问题的答案。请看我帖子的底部。

我在尝试以编程方式将didSelectRowAtIndexPath 中的UIViewController 推送到UITableView 时遇到动画问题。当我在 iOS 6 中运行此代码时,它运行良好。在 iOS 7 中,动画被弄乱了(它向左移动了大约 20% 的屏幕然后消失了)。如果我在情节提要中执行此操作,则动画很好。我是否遗漏了一些东西,或者有没有办法在不使用情节提要的情况下解决这个问题?

// This is a cut down example.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *viewController = [[UIViewController alloc] init];
    [self.navigationController pushViewController:viewController animated:YES];
}

这是 tableView 消失之前的样子。我明白它为什么这样做。这是因为被推送的新视图应该像使用情节提要一样动画滑入它。由于某种原因,它不能以编程方式工作。

编辑:这就是我错过的全部 出于某种原因,您必须设置背景颜色。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *viewController = [[UIViewController alloc] init];
    [viewController.view setBackgroundColor:[UIColor orangeColor]];
    [self.navigationController pushViewController:viewController animated:YES];
}

【问题讨论】:

  • 您是否尝试过将其放在 UIView 动画块中,然后将动画设置为 NO 作为解决方法?
  • 是您没有看到将viewController 推入堆栈的问题的一部分吗?还是只是旧的viewController 仅向左移动了大约 20% 的问题?
  • 我的 ViewController 出现了。是动画不能正常工作。
  • 我认为您需要在视图中包含内容或设置背景。但我不知道为什么...

标签: ios uitableview uinavigationcontroller ios7


【解决方案1】:

我也遇到过这个问题。另一个原因是修改目标视图的 alpha。至少那是我所做的。

如果您想在显示加载 HUD 或其他内容时更改视图的不透明度,请不要修改视图的 alpha。 相反,请调整 Table View 或 Collection 视图的 alpha,或者您在该视图中拥有的任何内容。如果您有多个元素,请将它们全部放在一个视图中并更改该视图的 alpha。

如上所述,另一个原因也是背景颜色。您需要设置目标视图的背景颜色。我也遇到过几次。

【讨论】:

    【解决方案2】:

    我也遇到过类似的问题,但我设法通过延迟通话来解决

    [self performSelector:@selector(displayMyViewController) withObject:nil afterDelay:0.2f];
    

    【讨论】:

      【解决方案3】:

      这是 iOS7 中pushViewController:animated: 方法触发的默认“视差”行为。

      storyboards 几乎没有经验,我怀疑他们的segues 与UINavigationController 推送/弹出动画不同。

      您可以通过构建自定义animated 或自定义interactive 转换来覆盖默认推送/弹出。

      或者你可以使用UIViewControllermethod

      transitionFromViewController:toViewController:duration:options:animations:completion:
      

      自定义此行为。希望这会有所帮助,并希望我已经理解您的问题...

      【讨论】:

      • 是的,您理解我的问题,但我相信:transitionFromViewController:toViewController:duration:options:animations:completion: 不适用于 UINavigation pushViewController。
      • 是的,你是对的,我应该提到这一点。我的意思是说,如果你想走 UIViewController 遏制的路线,这种方法是可能的......
      猜你喜欢
      • 1970-01-01
      • 2011-11-21
      • 2015-01-01
      • 2011-09-23
      • 1970-01-01
      • 2012-08-13
      • 2013-10-24
      • 2018-05-26
      相关资源
      最近更新 更多