xiubojin / JXBWKWebView

An component WebView for iOS base on WKWebView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

自定义返回键失败

D-james opened this issue · comments

  • (void)updateNavigationItems {
    if (self.webView.canGoBack) {
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    if (self.showCloseNavLeftItem){
    [self.navigationItem setLeftBarButtonItems:@[self.backNavLeftItem, self.closeNavLeftItem] animated:NO];
    }else{
    [self.navigationItem setLeftBarButtonItems:@[self.backNavLeftItem] animated:NO];
    }
    } else {
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    [self.navigationItem setLeftBarButtonItems:nil animated:NO];
    }
    }
    我是继承JXBWebViewController,然后设置leftBarButtonItem,一直无效,发现是这里覆盖了。这里应该判断是第一页Webview的话就不隐藏,或者是我用错了,大佬指点下
commented

你的需求是啥样的

你的需求是啥样的

就是要自定义返回按钮

commented

那你给backItem重新赋个值不就行了吗

那你给backItem重新赋个值不就行了吗

(void)updateNavigationItems {
if (self.webView.canGoBack) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
if (self.showCloseNavLeftItem){
[self.navigationItem setLeftBarButtonItems:@[self.backNavLeftItem, self.closeNavLeftItem] animated:NO];
}else{
[self.navigationItem setLeftBarButtonItems:@[self.backNavLeftItem] animated:NO];
}
} else {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
[self.navigationItem setLeftBarButtonItems:nil animated:NO];
}
}
上面代码会执行
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
[self.navigationItem setLeftBarButtonItems:nil animated:NO];
然后设置的就被重写了

commented

你重写backNavLeftItem的getter方法

backNavLeftItem

backNavLeftItem是私有属性,没有暴露在.h中,能否修改下源码,让设置返回键更方便一点。
@Property (nonatomic, copy) NSString *backImagePath; //返回按钮图片的路径(默认为当前库的资源bundle)
这个属性是不生效的,也会被updateNavigationItems方法覆盖

commented

pod 'JXBWebKit', '~> 1.2.0'

最新版本已经都暴露出来了

更新了最新版本,建议大佬把这个属性生效@Property (nonatomic, copy) NSString *backImagePath;,不然自定义返回按钮太不方便了,如果直接设置backItem,会有闪烁,重写backItem的get方法,因为是子类重写父类的get方法,需要在子类实现@dynamic backItem;自定扩展定义@Property (strong, nonatomic) UIBarButtonItem *_backItem;,然后再重写set,get方法,太麻烦了,希望直接设置的backImagePath能够生效

commented

backImagePath其实是生效的,之所以这个属性名叫path是希望你能把图片的完整路径传给我,因为有的项目可能会把三方库集成到一起,集成之后的大库可能是动态库,可能是静态库,这个是我没法判断的。