编辑:我找到了我自己问题的答案。请查看我的帖子底部。
我在尝试以编程方式在 UITableView
上推送 didSelectRowAtIndexPath
中的 UIViewController
时遇到动画问题。当我在 iOS 6 中运行这段代码时,它工作正常。在 iOS 7 中,动画被搞砸了(它向左移动大约 20% 的屏幕然后消失)。如果我在 Storyboard 中这样做,动画就很好。我是不是遗漏了什么或者有没有不使用 Storyboard的解决方法?
// 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 消失之前的样子。我明白它为什么这样做。这是因为被推送的新 View 应该像使用 Storyboard时一样在其上滑动。由于某种原因,它无法以编程方式工作。
编辑:这就是我错过的一切 出于某种原因,您必须设置背景颜色。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *viewController = [[UIViewController alloc] init];
[viewController.view setBackgroundColor:[UIColor orangeColor]];
[self.navigationController pushViewController:viewController animated:YES];
}
最佳答案
这是 iOS7 中 pushViewController:animated:
方法触发的默认“视差”行为。
对 storyboards
经验不足,我怀疑它们的 segue
与 UINavigationController
推送/弹出动画不同。
您可以通过构建自定义 animated 来覆盖默认的 push/pop或自定义 interactive过渡。
或者您可以使用UIViewController
method :
transitionFromViewController:toViewController:duration:options:animations:completion:
自定义此行为。希望这对您有所帮助,并希望我已经理解您的问题...
关于iOS 7 UITableView didSelectRowAtIndexPath pushViewController 编程,动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19255657/