iOS 7 UITableView didSelectRowAtIndexPath pushViewController以编程方式,动画问题

Jay*_*bit 11 uitableview uinavigationcontroller ios ios7

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

我有一个动画的问题试图推动一个UIViewControllerdidSelectRowAtIndexPath上一个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];
}
Run Code Online (Sandbox Code Playgroud)

这就是tableView消失之前的样子.我明白为什么会这样做.这是因为推送的新视图应该像使用故事板时那样在其上滑动.由于某种原因,它不能以编程方式工作.

在此输入图像描述

编辑:这是我错过的所有 由于某种原因你必须设置backgroundColor.

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

Alf*_*sen 2

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

由于缺乏经验,storyboards我怀疑它们的s 与推送/弹出动画segue不同。UINavigationController

您可以通过构建自定义动画或自定义交互式过渡来覆盖默认的推送/弹出。

或者你可以使用以下UIViewController 方法

transitionFromViewController:toViewController:duration:options:animations:completion:
Run Code Online (Sandbox Code Playgroud)

自定义此行为。希望这有帮助,并希望我能理解你的问题......