UIWebView原生跳转界面PUSH POP
来源:互联网 发布:域策略禁止安装软件 编辑:程序博客网 时间:2024/06/03 23:01
事情发生在CocoaChina论坛上,看到一个妹子遇到webview push出去后返回回来一片空白,于是就跟妹子要了链接.自己写个代码试了下.
至于为什么空白我也没有想到原因,可能是webview的机制吧..
哪位大神有更好的解决办法可以告诉我下
关于避免空白我是这么做的
写个NavigationController继承自UINavigationController
写个代理获取pop事件
//// BaseNavigationController.h// Test//// Created by XuTianyu on 16/3/8.// Copyright © 2016年 lakala. All rights reserved.//#import <UIKit/UIKit.h>@protocol UINavigationBackDelegate <NSObject>@optional/** * 点击返回按钮 * * @param viewcontroller 返回按钮点击后的界面 */-(void)navigationBackButtonClickedWithViewController:(UIViewController *)viewcontroller;@end@interface BaseNavigationController : UINavigationController@property (weak, nonatomic)id<UINavigationBackDelegate>backDelegate;@end
//// BaseNavigationController.m// Test//// Created by XuTianyu on 16/3/8.// Copyright © 2016年 lakala. All rights reserved.//#import "BaseNavigationController.h"@implementation BaseNavigationController-(UIViewController *)popViewControllerAnimated:(BOOL)animated{ //获取当前viewControllers NSArray *vcs = self.viewControllers; //这个方法返回的是后退按钮所在的viewcontroller UIViewController * viewController = [super popViewControllerAnimated:animated]; if ([self.backDelegate respondsToSelector:@selector(navigationBackButtonClickedWithViewController:)]) { //获取当前viewcontroller的下标 NSInteger currentIndex = [vcs indexOfObject:viewController]; //获取前一个viewcontroller UIViewController *backToVC = vcs[currentIndex - 1]; [self.backDelegate navigationBackButtonClickedWithViewController:backToVC]; } return nil;}@end
然后在代理方法里面做下处理
-(void)navigationBackButtonClickedWithViewController:(UIViewController *)viewcontroller{ if ([viewcontroller isKindOfClass:[WebViewController class]]) { //如果pop回来的界面是web,就reload下,解决空白问题 WebViewController *backViewController = (WebViewController *)viewcontroller; [backViewController.webView reload]; }}
<pre name="code" class="objc">//// WebViewController.m// Test//// Created by XuTianyu on 16/3/2.// Copyright © 2016年 lakala. All rights reserved.//#import "WebViewController.h"@interface WebViewController ()<UIWebViewDelegate>@end@implementation WebViewController-(UIWebView *)webView{ if (!_webView) { _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; _webView.delegate = self; _webView.scalesPageToFit = YES; _webView.contentMode = UIViewContentModeScaleAspectFit; } return _webView;}-(void)loadData{ //加载网页 NSURLRequest *request=[NSURLRequest requestWithURL:self.url]; [self.webView loadRequest:request];}- (void)viewDidLoad { [super viewDidLoad]; [self loadData]; [self.view addSubview:self.webView]; // Do any additional setup after loading the view.}//获取网页标题-(void)webViewDidFinishLoad:(UIWebView *)webView{ self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];}-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ //如果跳转的网址跟当前界面生成时的网址一样 就不在本页面处理.push一个新的页面 if (![request.URL.absoluteString isEqualToString:self.url.absoluteString]) { WebViewController *webviewVC = [[WebViewController alloc] init]; webviewVC.url = request.URL; [self.navigationController pushViewController:webviewVC animated:YES]; return NO; }else return YES;}@end
0 0
- UIWebView原生跳转界面PUSH POP
- 自定义PUSH POP跳转动画
- 利用runTime实现UIWebView 与 JS 随意交互,JS跳转原生页面,亦可实现推送界面万能动态跳转
- navigationController push和pop界面切换动画
- 原生js中关于array的方法--pop()和push()
- React native 界面跳转原生Android界面
- PUSH/POP
- IOS - 页面跳转及返回 (push-pop,modal-dismiss)
- Swift基础之自定义PUSH和POP跳转动画
- 更改navigationController push和pop界面切换动画
- 更改navigationController push和pop界面切换动画
- 更改navigationController push和pop界面切换动画
- 更改navigationController push和pop界面切换动画
- iOS:更改navigationController push和pop界面切换动画
- 更改navigationController push和pop界面切换动画
- 更改navigationController push和pop界面切换动画
- 更改navigationController push和pop界面切换动画
- 更改navigationController push和pop界面切换动画
- java学习笔记:条件判断
- Layout 布局 mmmm ぃ→ ぷ彪翻译。不当之处,敬请指正
- Java设计模式—单例设计模式(Singleton Pattern)完全解析
- Android框架——下载图片框架Fresco
- linq to Entity 数据格式转换 SqlFunctions
- UIWebView原生跳转界面PUSH POP
- RAC 和 Oracle Clusterware 最佳实践和初学者指南 (AIX) (文档 ID 1526555.1)
- hadoop 2.0最多支持多少个结点
- C++中的单例模式
- sizeof与strlen的区别
- top命令
- iOS-动画进阶之路Core Animation
- C#中DLL调用资料整理
- 前端优化实践