iOS 7 UITableView didSelectRowAtIndexPath pushViewController以编程方式,动画问题 [英] iOS 7 UITableView didSelectRowAtIndexPath pushViewController programmatically, Animation issue

查看:78
本文介绍了iOS 7 UITableView didSelectRowAtIndexPath pushViewController以编程方式,动画问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我有一个动画问题试图推送 UIViewController 以编程方式在 UITableView 上的 didSelectRowAtIndexPath 中。当我在iOS 6中运行此代码时,它工作正常。在iOS 7中,动画混乱(它向左移动约20%的屏幕,然后消失)。如果我在故事板中这样做动画很好。我是否遗漏了一些东西,或者没有使用故事板可以解决这个问题吗?

I am having an animation issue trying to push a UIViewController in didSelectRowAtIndexPath on a UITableView programmatically. When I run this code in iOS 6 it works fine. In iOS 7 the animation is messed up (it animates to the left about 20% of the screen then disappears). If I do this in storyboard the animation is fine. Am I missing something or is there a way around this without using 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消失之前的样子。我明白为什么会这样做。这是因为推送的新视图应该像使用故事板时那样在其上滑动。由于某些原因,它不能以编程方式工作。

This is what it looks like right before the tableView disappears. I understand why it does this. Its because the new view being pushed should animate sliding in over it as it does when using storyboard. For some reason it does not work programmatically.

编辑:这是我错过的全部
出于某种原因,你必须设置一个backgroundColor。

This is all I missed For some reason you have to set a backgroundColor.

- (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:方法触发的行为。

This is the default "parallax" behavior triggered by the pushViewController:animated: method in iOS7.

故事板没什么经验我怀疑他们的 segue s与 UINavigationController 推/弹动画不同。

Having little experience with storyboards I suspect that their segues are different from UINavigationController push/pop animations.

您可以通过构建自定义动画或自定义交互式转换。

You can override the default push/pop by building custom animated or custom interactive transitions.

或者您可以使用 UIViewController 方法

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

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

to customize this behavior. Hope this helps and hope I've understood your question...

这篇关于iOS 7 UITableView didSelectRowAtIndexPath pushViewController以编程方式,动画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆