xiubojin / JXBWKWebView

An component WebView for iOS base on WKWebView
MIT License
736 stars 115 forks source link

自定义返回键失败 #69

Closed D-james closed 4 years ago

D-james commented 4 years ago
xiubojin commented 4 years ago

你的需求是啥样的

D-james commented 4 years ago

你的需求是啥样的

就是要自定义返回按钮

xiubojin commented 4 years ago

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

D-james commented 4 years ago

那你给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]; 然后设置的就被重写了

xiubojin commented 4 years ago

你重写backNavLeftItem的getter方法

D-james commented 4 years ago

backNavLeftItem

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

xiubojin commented 4 years ago

pod 'JXBWebKit', '~> 1.2.0'

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

D-james commented 4 years ago

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

xiubojin commented 4 years ago

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