Roxasora / RxWebViewController

实现类似微信的 webView 导航效果,包括进度条,左滑返回上个网页或者直接关闭,就像 UINavigationController
1.29k stars 207 forks source link

当前一个VC设置setNavigationBarHidden为YES的时候,第二次进入webVC的时候,返回有BUG #5

Open Regansun opened 8 years ago

Regansun commented 8 years ago

把当前VC设置setNavigationBarHidden为YES, 然后进入WebViewVC,点返回,页面返回当当前界面,再次进入,再点返回,页面就不会返回了,而且返回按钮也没用了! //当前VC设置代码

Roxasora commented 8 years ago

我复现一下~稍等

Regansun commented 8 years ago

问题解决了 //! 如果应该pop,说明是在 popViewController 之后,应该直接 popItems if (self.shouldPopItemAfterPopViewController) { self.shouldPopItemAfterPopViewController = NO; [self popViewControllerAnimated:YES]; //////加上这句就ok了! return YES; }

Roxasora commented 8 years ago

亲,可否把你的demo发给我看一下,这个地方这样设置可能会引起其他的问题。。

Regansun commented 8 years ago

我是在你的domo上直接改的,运行了下, 貌似别的地方也没影响

Regansun commented 8 years ago

好像是有问题,网页进入多级再返回就不对了

Regansun commented 8 years ago

-(BOOL)navigationBar:(UINavigationBar )navigationBar shouldPopItem:(UINavigationItem *)item{ //! 如果不应该 pop,说明是点击了导航栏的返回,这时候则要做出判断区分是不是在 webview 中 if ([self.topViewController isKindOfClass:[RxWebViewController class]]) { RxWebViewController webVC = (RxWebViewController*)self.viewControllers.lastObject; if (webVC.webView.canGoBack) { [webVC.webView goBack]; //!make sure the back indicator view alpha back to 1 self.shouldPopItemAfterPopViewController = NO; [[self.navigationBar subviews] lastObject].alpha = 1; return NO; }else{ [self popViewControllerAnimated:YES]; return NO; } }if (self.shouldPopItemAfterPopViewController) { //! 如果应该pop,说明是在 popViewController 之后,应该直接 popItems self.shouldPopItemAfterPopViewController = NO; return YES; }else{ [self popViewControllerAnimated:YES]; return NO; } } 这样判断的顺序换下,应该可以了/有可能还有问题

Roxasora commented 8 years ago

webviewController 的naviBar 是你自己设置的是吗? 我看你一开始隐藏了naviBar

Regansun commented 8 years ago

是用系统的,在第一个页面设置隐藏了,然后push以后的页面都不隐藏的

Regansun commented 8 years ago

好的,已经发你邮箱了

Regansun commented 8 years ago

之前修改的还是有问题,http://www.jianshu.com/p/6376149a2c4c 参考这个连接的貌似找到了完美解决的办法了

ynot16 commented 7 years ago

这个问题有解决方案了么?复现的步骤就像题目说的一样,前一个vc隐藏了导航栏,然后push到另一个没有隐藏导航栏的vc。第一次push,pop是正常的,但是第二次push之后,就pop不了。必现。

ynot16 commented 7 years ago

因为是隐藏导航栏出现的问题,我猜是self.shouldPopItemAfterPopViewController的记录出的问题。加了一下代码,貌似解决了 `- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated { self.shouldPopItemAfterPopViewController = hidden; [super setNavigationBarHidden:hidden animated:animated]; }