我有一个基于UIWebview
的应用,
当用户单击URL时,默认行为是立即显示空白页并等待页面加载
是否可以保留当前页面,直到加载下一页?
感谢您提前。
答案 0 :(得分:0)
我很好奇这种功能的必要性,我可能同意Chandra Vaghasiya的comment。
说过这是可能的。
UIWebView
。webViewDidStartLoad:
方法中,拍摄Web视图的快照,并在视图层次结构中的Web视图上方添加结果视图。webViewDidFinishLoad:
和webView:didFailLoadWithError:
方法中,只需隐藏快照视图。示例代码:
@interface ViewController () <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (nonatomic, strong) UIView *snapshotView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"https://google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
self.snapshotView = [self.webView snapshotViewAfterScreenUpdates:NO];
self.snapshotView.frame = self.webView.frame;
[self.view insertSubview:self.snapshotView
aboveSubview:self.webView];
self.snapshotView.hidden = NO;
// THIS IS JUST FOR DEMONSTRATION PURPOSES SO
// YOU CAN SEE THE LOADING HAPPENING BEHIND
// THE SNAPSHOT VIEW
self.snapshotView.alpha = 0.8;
NSLog(@"Display snapshot");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
self.snapshotView.hidden = YES;
NSLog(@"Hide snapshot");
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
self.snapshotView.hidden = YES;
NSLog(@"Hide snapshot due to error");
}
@end