Make a Flip animation (or something similar) when

2019-07-18 17:06发布

In one of my project i'm using only a UIWebView. I need an animation (for example a flip) when I reload my webView with another content... Is it possible to create a flip animation (or something similar)? I must create a fake controller to get it? Solutions? Thanks

2条回答
干净又极端
2楼-- · 2019-07-18 17:47

You can always do the +transitionWithView:duration:options:animations:completion: method with the web view.

[UIView transitionWithView:self.webView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionAllowAnimatedContent animations:
^{
    [self.webView loadHTMLString:@"<strong>Hello world</strong>" baseURL:nil];
} completion:^(BOOL finished)
{

}];

This method is basically a way of saying: "change the contents of this view, in animated fashion". So it takes an snapshot of the current state, performs the animation (be it a flip, curl, etc) and then inserts an snapshot of the new state.

But notice that I've used UIViewAnimationOptionAllowAnimatedContent, this forces the animation to not use a snapshot for the new state of the view, because setting loadHTMLString does not change the view immediately, so we need to force it to use the live context of the view instead of a snapshot.

The weather app in iOS (pre 7) uses a similar method for alternating between the current weather and the picker for other regions/options when clicking the "i" on the bottom.

查看更多
Juvenile、少年°
3楼-- · 2019-07-18 18:02

I think that you don't need to create a controller for that. You can simply add something like that:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:yourView cache:YES];
[UIView commitAnimations];
查看更多
登录 后发表回答