问题
iOS 6.1
When a button is tapped, I want to perform a transition from an imageview to a webview. The problem is that the very first time the webview loads, the page is white and the html page loads after the transition:
NepContainerView *containerInFrame = (NepContainerView *)[self view];
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
[webView loadHTMLString:html baseURL:nil];
[UIView transitionWithView:containerInFrame
duration:DURATION_TRANS_PHOTO_DESC
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[containerInFrame addSubview:webView];
[sender setTitle:@" Photo "];
}
completion:NULL];
How can I force the html page to be loaded before the transition?
回答1:
you can also use this WebContentView library.
this library have one method named as
+ (void)preloadContent:(NSString *)content;
You can use this method to preload the content so that it will render fast.
hope it helps.
Here is the useful link that will help you
Preloading a UIWebView, avoiding white screen flash
回答2:
You have to set delegate of UIWebView and when
- (void)webViewDidFinishLoad:(UIWebView *)webView;
will called then call your method for transition
[UIView transitionWithView:containerInFrame
duration:DURATION_TRANS_PHOTO_DESC
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[containerInFrame addSubview:webView];
[sender setTitle:@" Photo "];
}
completion:NULL];
来源:https://stackoverflow.com/questions/18437792/how-to-force-uiwebview-to-load-before-transition