I’ve got a view that contains a UIWebView (With text images, etc) that is attached to a GestureRecognizer. Once the webView is “tapped,” it flips over and displays updated text, images, etc. on this web view. I have the action associated with this recognizer as follows:
- (IBAction)flipWebViewGestureRecognizer:(id)sender
{
// isFrontView is boolean to determine if card is front or back
if(self.isFrontOfView)
{
self.isFrontOfView = NO;
[UIView transitionWithView: self.imageView
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromTop
animations: ^{ [self loadBack]; }
completion: nil];
}
else
{
self.isFrontOfView = YES;
[UIView transitionWithView: self.imageView
duration: 1.0
options: UIViewAnimationOptionTransitionFlipFromTop
animations: ^{ [self loadFront]; }
completion: nil];
}
}
The methods loadFront and loadBack are as follows (html itself is shortened to minimum):
- (void) loadFront
{
NSString *html = @"<p>Front Of Card</p>";
[self.viewWebView loadHTMLString:html baseURL:nil];
}
- (void) loadBack
{
NSString *html = @"<p>Front Of Card</p> <br /> <p>as well as back of card<p>";
[self.viewWebView loadHTMLString:html baseURL:nil];
}
From a functionality perspective this works great. The card can be flipped, and the web view is updated with the new HTML text. However, the update to the actual web view takes place after the card has already finished flipping (after the animation instead of during). What do I need to do to have the viewWebView already loaded with the updated html once the view animation finishes it’s flip, rather than immediately afterwards.
I believe your problem is that UIWebView loads items asynchronously. If so, you need to start your load and then when the UIWebView calls the delegate function
webViewDidFinishLoad:begin your animation.However, it’s possible that the UIWebView will render to the screen before the delegate method is called causing the content to flash up before the animation begins.
If so, then you may have to do this with two different UIWebViews and animate switching from one to the other.