[英]UINavigationController Interactive Pop Gesture only works first time
I have been working on an app for some time and just realized the swiping back in the detail view only returns me to the master view the first time.我已经在一个应用程序上工作了一段时间,刚刚意识到在详细信息视图中向后滑动只会让我第一次返回主视图。 It also isn't smooth, even when it works on the first time.
它也不是很顺利,即使它是第一次运行。 Instead of smoothly going to the master view, it jumps all at once, even when I swipe slowly.
它不是顺利进入主视图,而是一下子跳转,即使我慢慢滑动也是如此。 It used to work correctly, but I haven't been testing for this specifically, so I don't know when it stopped working and what I changed to cause this.
它曾经可以正常工作,但我没有专门为此进行过测试,所以我不知道它何时停止工作以及我更改了什么导致了这种情况。
A little about how my app is setup...关于我的应用程序如何设置的一点...
I have a split view controller that is connected to my MasterTableViewController
and DetailViewController
.我有一个连接到我的
MasterTableViewController
和DetailViewController
的拆分视图控制器。
Both of those are have TableViews and are embedded in Navigation Controllers.这两个都有 TableViews 并嵌入在导航控制器中。
I have set it up so that the app originally loads to the MasterTableViewController instead of going immediately to the DetailViewController, but even when I take this out, the interactive pop gesture doesn't work.我已经设置好应用程序最初加载到 MasterTableViewController 而不是立即转到 DetailViewController,但即使我取出它,交互式弹出手势也不起作用。
I don't believe I've messed with any of the back button controls.我不相信我弄乱了任何后退按钮控件。 I have looked through my code and storyboard and can't find anywhere that I have.
我查看了我的代码和故事板,但找不到任何地方。 This is part of what is most confusing because these questions ( 1 , 2 , and 3 ) all seem to have problems stemming from changing the back button or can be fixed by entering the following line of code:
这是最令人困惑的部分,因为这些问题( 1 、 2和3 )似乎都有来自更改后退按钮的问题,或者可以通过输入以下代码行来修复:
self.navigationController.interactivePopGestureRecognizer.delegate = nil
Adding that to my code seems to have no impact on how it behaves.将其添加到我的代码中似乎对其行为方式没有影响。
Here is a picture of how it is setup for reference:这是如何设置的图片以供参考:
I can usually figure out these things on my own, but this problem baffles me because it works the first time, but not any others.我通常可以自己解决这些问题,但这个问题让我感到困惑,因为它第一次有效,但其他任何时候都无效。 As far as I can tell, nothing changes between the first time and the others.
据我所知,第一次和其他时间之间没有任何变化。 I don't know if anybody else has had the same issue, but any help on why this might be happening would be greatly appreciated.
我不知道是否有其他人遇到过同样的问题,但是对于为什么会发生这种情况的任何帮助将不胜感激。 I can provide code or answers to questions on how I am doing certain things if needed.
如果需要,我可以提供有关我如何做某些事情的问题的代码或答案。 I haven't put any in because there are so many different things controlling this piece that I don't know where to start.
我没有放任何东西,因为控制这件作品的东西太多了,我不知道从哪里开始。
From Alex Chase's answer : Also check your overrides of viewWillAppear
in child ViewControllers
.来自Alex Chase 的回答:还要检查您在子
ViewControllers
对viewWillAppear
的覆盖。 This method gets called during an interactive pop.在交互式弹出期间调用此方法。
added it to viewWillAppear
and it worked:将它添加到
viewWillAppear
并且它起作用了:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.interactivePopGestureRecognizer?.delegate = self
}
When are you calling self.navigationController.interactivePopGestureRecognizer.delegate = nil
?你什么时候调用
self.navigationController.interactivePopGestureRecognizer.delegate = nil
? Doing this will definitely disable interactive pop.这样做肯定会禁用交互式流行音乐。 It sounds like you may be calling this after a certain
UIViewController
appears.听起来您可能会在某个
UIViewController
出现后调用它。
What other modifications to UINavigationController
are you making?您对
UINavigationController
进行了哪些其他修改? Are you using appearance delegate?你在使用外观委托吗? Are you subclassing?
你是子类化吗? If so, are you calling
super
in all of your method overrides?如果是这样,您是否在所有方法覆盖中调用
super
?
Also check your overrides of viewWillAppear
in child ViewControllers.还要检查您在子 ViewControllers 中对
viewWillAppear
的覆盖。 This method gets called during an interactive pop.在交互式弹出期间调用此方法。 If you are doing a lot of computation (or synchronous calls) on the main thread within this method, it could cause frame drop, hence the choppy animation.
如果您在此方法中的主线程上进行大量计算(或同步调用),则可能会导致掉帧,从而导致动画断断续续。
Hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.