简体   繁体   English

ios7 navigationController pushViewController动画bug

[英]ios7 navigationController pushViewController animated bug

It looks like I found a bug in the navigationController pushViewController method. 看起来我在navigationController pushViewController方法中发现了一个错误。 To recreate it I took the sample master detail project and made some changes to the -didSelectRow: method: 为了重新创建它,我采用了示例主详细信息项目并对-didSelectRow:方法进行了一些更改:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController* view = [self.storyboard instantiateViewControllerWithIdentifier: @"view"];
    NSDate *object = _objects[indexPath.row];
    [view setDetailItem:object];
    [self.detailViewController.navigationController pushViewController:view animated:YES];
}

I also changed the storyboard ID of the detail view to "view". 我还将详细视图的故事板ID更改为“查看”。 Here's what happens: 这是发生的事情:

When selecting any of master's rows slowly (when the push animation has finished) it works fine: 当慢慢选择任何主人的行时(当推动画完成时),它可以正常工作: 慢慢选择行

If you select any of the rows while the animation is still showing, the detail view becomes inactive (shows the last row that was called with the push method before the bug) and only the navigation bar shows the push animation of a new view: 如果在动画仍显示时选择任何行,则详细视图将变为非活动状态(显示在错误之前使用push方法调用的最后一行),并且只有导航栏显示新视图的推送动画: 快速选择行

When this happens you get some warnings in the debugger output: 发生这种情况时,您会在调试器输出中收到一些警告:

Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

nested push animation can result in corrupted navigation bar

Unbalanced calls to begin/end appearance transitions for <DetailViewController: 0x8a6e070>.

Here's the nasty part: if you go back on the detail view's navigation bar and then select a different row in Master's tableview OR go back twice in the Detail the app crashes with 这是令人讨厌的部分:如果你回到详细视图的导航栏然后在Master的tableview中选择一个不同的行,或者在详细信息中返回两次应用程序崩溃

Can't add self as subview

BUT if you run the same code on ios6 it works without any problems or warnings. 但是,如果您在ios6上运行相同的代码,它可以正常工作,没有任何问题或警告。

Current solutions: 目前解决方案

Calling the method with animated:NO seems to work without any problems, obviously there's no push animation. 用动画调用方法:NO似乎没有任何问题,显然没有推动画。

Another solution is to have a boolean value in Master set it to false when calling the push method and setting it to true from Detail in Detail's viewDidAppear. 另一种解决方案是在Master中设置一个布尔值,在调用push方法时将其设置为false,并从Detail in Detail的viewDidAppear中将其设置为true。 That way you can check the value when calling the push method. 这样,您可以在调用push方法时检查该值。 Drawbacks: the tableView might appear laggy if you try to quickly select the same row, if you select a different row quickly then it wont show up in Detail but it will get selected in the Master tableview and get highlighted, you can save the selected row's index and change the selection in code but that leads to flickering row highlighting. 缺点:如果您尝试快速选择同一行,tableView可能会显得滞后,如果您快速选择另一行然后它不会显示在详细信息中但它将在主表视图中被选中并突出显示,您可以保存所选行的索引并更改代码中的选择,但这会导致闪烁的行突出显示。

Both solutions involve some compromise, so I'd like to find another way of handling this. 这两个解决方案都有一些妥协,所以我想找到另一种处理方法。 Are there any better solutions? 还有更好的解决方案吗?

After some testing it appears that in ios6 when a tableview cell gets selected and the push gets called the tableview sets .allowsSelection to NO until the push ends. 经过一些测试后,在ios6中,当一个tableview单元被选中并且push被调用时,tableview .allowsSelection设置为NO直到push结束。

This can be easily reproduced in ios7 by setting .allowsSelection to NO after the push method in didSelectRowAtIndexPath: and having a callback in the didAppear: method of the detail's view where we set the tableview's .allowsSelection to YES in the master view. 这可以在ios7通过设置容易地再现.allowsSelectionNO在推方法之后didSelectRowAtIndexPath:和具有在一个回调didAppear:我们的tableview中的设置的细节的视图的方法.allowsSelectionYES在主视图。

While this works perfectly fine I found it a bit annoying when quickly selecting two different cells one after the other that the second one will get ignored. 虽然这种方法非常好,但我发现在一个接一个地快速选择两个不同的单元格时会觉得有点烦人,第二个单元格会被忽略。

So i've set up that if another cell is being selected while the push animation hasn't ended I save a reference to the new view and push it as soon as the first animation has ended. 所以我设置了如果在推动动画尚未结束时选择另一个单元格,我将保存对新视图的引用并在第一个动画结束后立即推送它。 By doing this the tableView seems a bit more responsive in my opinion. 通过这样做,tableView在我看来似乎更敏感。

The reason behind your is pushing a view controller while the other hasn't been fully pushed (logs already warns you from doing so). 你背后的原因是推动一个视图控制器,而另一个没有完全推动(日志已警告你这样做)。

The push animation is supposed to take approx 0.4 sec, so the user has to be fast enough to tap another row within 0.4 sec, yes that is applicable, but isn't a normal behavior. 推动动画应该花费大约0.4秒,因此用户必须足够快以在0.4秒内敲击另一行,是的,这是适用的,但不是正常行为。

what you can do is to edit the animation time to be less than 0.4 sec (may be 0.1 or 0.2) using the code below in your -didSelectRow: method: 您可以做的是使用-didSelectRow:方法中的以下代码将动画时间编辑为小于0.4秒(可能是0.1或0.2):

DetailViewController* view = [self.storyboard instantiateViewControllerWithIdentifier: @"view"];
NSDate *object = _objects[indexPath.row];
[view setDetailItem:object];

[UIView  beginAnimations:@"ShowDetails" context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.2];
[self.detailViewController.navigationController pushViewController:view animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

Hope it helps :) 希望能帮助到你 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS NavigationController pushViewController不起作用 - iOS navigationController pushViewController not working IOS7中的PushViewController崩溃 - PushViewController Crash in IOS7 pushviewcontroller在ios7中不起作用 - pushviewcontroller is not working in ios7 iOS-调用方法:[self.navigationController pushViewController:animated:],屏幕变黑 - iOS - call the method : [self.navigationController pushViewController: animated:], the screen get whole black iOS7 UINavigationController pushViewController:通过动画进行背靠背动画锁定主线程 - iOS7 UINavigationController pushViewController:animated back to back with animation locks up the main thread iOS NavigationController pushViewController第一次很慢 - IOS navigationController pushViewController very slow in first time 关于self.navigationController pushViewController(IOS) - about self.navigationController pushViewController (IOS) self.navigationController pushViewController:动画:给我一个黑屏 - self.navigationController pushViewController: animated: gives me a black screen [self.navigationController pushViewController:ngView animated:YES]; 不工作 - [self.navigationController pushViewController:ngView animated:YES]; not working 使用 self.navigationController 时出现问题?.pushViewController(newViewController, animated: true) - Problems using self.navigationController?.pushViewController(newViewController, animated: true)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM