我在从右到左滑动手势后为webview加载新内容。执行手势后,webview会加载其新内容。如何为此webview制作动画,该动画会根据手势显示webview内容的“滑动”?因此,当用户从右向左滑动时,webview也应该从右向左移动。并最终“飞走”。我认为有些音乐应用可以通过刷一个来加载新音轨。谢谢!
答案 0 :(得分:8)
您可以按照以下代码应用单个UIWebView
的滑动动画。
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *recognizerRight;
recognizerRight.delegate=self;
recognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
[recognizerRight setDirection:UISwipeGestureRecognizerDirectionRight];
[webView addGestureRecognizer:recognizerRight];
UISwipeGestureRecognizer *recognizerLeft;
recognizerLeft.delegate=self;
recognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeleft:)];
[recognizerLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[webView addGestureRecognizer:recognizerLeft];
}
现在在CATransition
的帮助下应用了滑动效果。
-(void)swipeleft:(UISwipeGestureRecognizer *)swipeGesture
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setDuration:0.50];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[webView.layer addAnimation:animation forKey:kCATransition];
}
-(void)swipeRight:(UISwipeGestureRecognizer *)swipeGesture
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setDuration:0.40];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[webView.layer addAnimation:animation forKey:kCATransition];
}
希望这对你有所帮助。
答案 1 :(得分:1)
您需要使用两个UIWebViews,一个飞走,一个用于新内容。为了让它飞走,您可以使用其中一个库,例如ZLSwipeableView。
同时,我会在第一个位置创建一个新的UIWebView。您可能应该首先使其不可见,并根据第一个视图的移动使其可见,以便逐渐显示。
答案 2 :(得分:0)
对于滑动手势并加载新内容,您可以使用:
UISwipeGestureRecognizer *swipeGR;
swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft)];
swipeGR.direction = UISwipeGestureRecognizerDirectionLeft;
swipeGR.delegate = self;
swipeGR.numberOfTouchesRequired = 1;
[webview addGestureRecognizer:swipeGR];