Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rt_disableInteractivePop 被多次设置后无作用 #47

Closed
PatShen opened this issue Feb 22, 2017 · 10 comments
Closed

rt_disableInteractivePop 被多次设置后无作用 #47

PatShen opened this issue Feb 22, 2017 · 10 comments

Comments

@PatShen
Copy link

PatShen commented Feb 22, 2017

我在demo的RTWebViewController界面中,添加了一个按钮,事件是每次点击,当前controller的rt_disableInteractivePop置非,
即:self.rt_disableInteractivePop = !self.rt_disableInteractivePop

在执行这个方法前能划出屏幕的情况下,执行之后,依旧能够划出屏幕(正常应该不能再划出了);
反之亦然;

真实的使用场景例如在 WKWebview 中,设置webview 的allowsBackForwardNavigationGestures 为yes,如果 webivew 的 canGoBack 的值是 YES,此时就不应该触发滑动退出页面的事件,而应该触发webview的goBack事件(类似微信的webview)

根据我的观察,存在以下几种情况
1.在viewDidLoad方法中设置 rt_disableInteractivePop 的值会生效;
2.WKWebview有缓存后,根据webview的状态(是否能goBack)在主线程重新设置rt_disableInteractivePop的值会生效;

@rickytan
Copy link
Owner

这个属性只在 - (void)viewDidLoad: 设置一次有效,之后的改变是无效的,就像:

self.extendedLayoutIncludesOpaqueBars;
self.automaticallyAdjustsScrollViewInsets;
self.edgesForExtendedLayout;

等属性一样

@PatShen
Copy link
Author

PatShen commented Feb 27, 2017

如果想要在某个ViewController的生命周期中,控制可划出/不可划出,还有其他方式实现吗?

@rickytan
Copy link
Owner

不能一开始就确定吗?如果用户手势返回滑到一半,突然又禁止呢?

@PatShen
Copy link
Author

PatShen commented Feb 28, 2017

是这样子的,iOS8新增的WKWebview,可以通过右滑来返回上一页。
如果一开始确定手势为开启的话,会将WKWebview的右滑手势屏蔽...这里的话我想通过判断WKWebview是否可以返回(canBack)来判断手势是否应该开启。

@rickytan
Copy link
Owner

rickytan commented Mar 1, 2017

试试:

self.rt_navigationController.interactivePopGestureRecognizer.enabled = !self.webView.canGoBack;

但是记得 vc 消失时还原设置

@PatShen
Copy link
Author

PatShen commented Mar 1, 2017

这个可以!非常感谢!

@PatShen PatShen closed this as completed Mar 1, 2017
@ucoker
Copy link

ucoker commented Sep 12, 2017

可行,感谢🙏

@rickytan
Copy link
Owner

使用手势依赖应该更科学点:#104 (comment)

@KearLiao
Copy link

image
每次这个都被会设置一次 然后我在viewDidload里面设置 禁止 就失效?

@rickytan
Copy link
Owner

@KearLiao 不会每次都改,还有个条件 rt_hasSetInteractivePop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants