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

标签 ios uitableview uinavigationcontroller ios7

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

我在尝试以编程方式在 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时一样在其上滑动。由于某种原因,它无法以编程方式工作。

enter image description here

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

- (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 经验不足,我怀疑它们的 segueUINavigationController 推送/弹出动画不同。

您可以通过构建自定义 animated 来覆盖默认的 push/pop或自定义 interactive过渡。

或者您可以使用UIViewController method :

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

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

关于iOS 7 UITableView didSelectRowAtIndexPath pushViewController 编程,动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19255657/

相关文章:

ios - 如何在没有 NavigationController 的情况下使用 ASTableNode 在 ASViewController 上添加像 Navigationbar 这样的 headerView?

ios - 使用XCode 7 beta 4将项目更新到iOS 9

具有动态高度的 UITableViewCell 中的 iOS 芯片

ios - 如何使 UIBarButtonItem 在按下时执行功能?

ios - 将 UITableViewController 推送到导航堆栈失败

c# - 使用 Instagram API 将图片上传到 Instagram

ios - SDWebImage 使用 UIGraphicsBeginImageContextWithOptions 调整大小

ios - 添加新行时 UITableView 停止滚动

ios - 点击按钮时用新部分填充 UItableView

ios - iOS 5 中的 View Controller 有什么方法可以指定要在导航堆栈推送上的后退按钮中使用的图像吗?