Roxasora / RxWebViewController

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

自己写导航栏时,即设置navigation bar的hidden为yes会出现pop问题 #2

Open JimWithJiang opened 8 years ago

JimWithJiang commented 8 years ago

navigationBar.hidden在viewAppear与view Disappear里执行, 点击的返回按钮是自己写得,点击后发现 [self popViewControllerAnimated:YES]会执行2次,导致每次都POP到rootViewController。我尝试在拦截里通过navigationBar.hidden判断,但是没有效果。在这里我建议是否可以在跳到网页的时候,自己写一个navigation bar,然后在拦截里通过navigation bar的类型判断,当然这个navigation bar的样式依旧可以自定义,在这里非常感谢您提供了这么好用加载网页框架!

Roxasora commented 8 years ago

我明白你的问题了,我这边尝试重现一下吧,或者你可否把一部分代码给我看一下,这个自己写的返回按钮是viewController中的一个类似“退出”的button,不是navigationBar上的backButton是吧~

JimWithJiang commented 8 years ago

是的,就是把navigationBar隐藏,为了达到满足各种效果,自己用UIView模拟的导航栏,点击调用 [self popViewControllerAnimated:YES],这种情况下就会类似多米诺骨牌,pop到rootViewController。我现在可以通过把你写得RxWebViewController的navigationBar隐藏,自己也这样写,暂时可解决这问题。我这有demo,需要的话您告诉我下邮件地址或发我邮件jiangming0614@126.com,我把demo给你。

Roxasora commented 8 years ago

roxasora.g@gmail.com 最近工作比较忙,抱歉可能不能及时回复,周末我会抽时间解决这个问题!谢谢反馈!!

Roxasora commented 8 years ago

应该解决了,问题出在

    -(BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item{
        if ([self.viewControllers.lastObject class] == [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.navigationBar subviews] lastObject].alpha = 1;
                return NO;
            }else{
                [self popViewControllerAnimated:YES];
                return YES;
            }
        }
        return YES;
    }

这里,如果当前 VC 是RxWebViewController 才应该执行 pop 动作,否则应该交给系统处理

tanranran commented 8 years ago

上面那段代码还是有问题.... 其它页面点击返回 会出现 页面不返回 但是 titile 返回的样子 ...屏蔽掉这段代码.就不会影响其它页面了

HHbreak commented 8 years ago

@tanranran 我这边也是,不知你解决了没有

MonkeyS914 commented 8 years ago

我也发现这个问题,后来发现作者 用下面这个方法截获系统返回操作时,没有处理不是 RxWebViewController class类的情况。-(BOOL)navigationBar:(UINavigationBar )navigationBar shouldPopItem:(UINavigationItem *)item{ if ([self.viewControllers.lastObject class] == [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.navigationBar subviews] lastObject].alpha = 1;
            return NO;
        }else{
            [self popViewControllerAnimated:YES];
            return YES;
        }
    }
    return YES;
}

即使在其他界面点击返回按钮,这段代码依然会截获到系统的pop事件,但是仔细看,你会发现,当viewController 不是RxWebViewController这个类时,这段代码没有处理,我是这样解决的 -(BOOL)navigationBar:(UINavigationBar )navigationBar shouldPopItem:(UINavigationItem *)item{ if ([self.viewControllers.lastObject class] == [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.navigationBar subviews] lastObject].alpha = 1;
        return NO;
    }else{
        [self popViewControllerAnimated:YES];
        return YES;
    }
}
else{

//加上else分句,当不是RxWebViewController,就直接执行pop操作 [self popViewControllerAnimated:YES]; } return YES; }

tanranran commented 8 years ago

@MonkeyS914 测试了下您的代码...还是有问题.

MonkeyS914 commented 8 years ago

还是你说的那个问题?导航栏返回了,但是页面没返回?我这边测试ok,其他的viewcontroller点击返回正常了

Roxasora commented 8 years ago

@MonkeyS914 @tanranran @HHbreak 我更新了代码,放弃了之前的 category,使用了新的 RxWebViewNavigationViewController,大家将自己的 navigationController 继承到这个上面,pop 普通页面会产生的问题应该都修复了,大家看一下,有问题随时联系我~ 谢谢!!

MonkeyS914 commented 8 years ago

其实你没必要拦截系统的这个返回事件

直接修改这个方法就好 -(void)customBackItemClicked{ if (self.webView.canGoBack) { [self.webView goBack]; } else { [self.navigationController popViewControllerAnimated:YES]; } }

Roxasora commented 8 years ago

@MonkeyS914 你这里的 customBackItemClicked 方法是自己 subclass RxWebViewController 的时候添加的对吧,用于你自己重写了导航栏的状况是没问题的,但是如果是没有重写,仅仅是用系统提供的导航栏的情况是不是必须要拦截这个事件了呢~ 所以你的这种情况,其实可以把我的 category 或者 NavigationController 部分删掉,然后再加上你的这个方法就没问题了~~ 感谢回复和支持~

MonkeyS914 commented 8 years ago

这个是你RxWebViewController 写的,我只是改了一下,因为觉得把我自己的navigationcontroller继承到你的那个NavigationController 感觉有点麻烦,于是就直接把demo里面的category删除了,修改了下你的返回的item响应方法。您的的这个效果实现思路很special,学习了,哈哈!

1xiaocainiao commented 8 years ago

我也出现了楼上的bug,第一次正常进入web,退出,再次进入,点击返回就依然停留在web页面了.push之前的页面是隐藏了导航栏的,其他页面的导航栏是显示的