I´m loading new content for a webview after a right to left swipe gesture. After the gesture is performed the webview loads its new content. How can I make an animation for this webview which displays a "swiping-away" of the webview´s content accordingly to the gesture? So while the user is swiping from right to left the webview should also be moved from right to left. And eventually "fly away". I think some music apps have this where you can load a new track by swiping one away. Thanks!
You can applied swipe animation with single UIWebView by following below code.
- (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];
}
Now applied swipe effect with help of 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];
}
Hope this help you.
You will need to use two UIWebViews the one that is flying away and one for the new content. To make it fly away you can just use one of the many libraries out there such as ZLSwipeableView.
In parallel, I would use create a new UIWebView on the location of the first. You should probably make it invisible at first and make it's visibility based on the movement of the first view so it gradually appears.
For swipe gesture and load a new content, you can use:
UISwipeGestureRecognizer *swipeGR;
swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeLeft)];
swipeGR.direction = UISwipeGestureRecognizerDirectionLeft;
swipeGR.delegate = self;
swipeGR.numberOfTouchesRequired = 1;
[webview addGestureRecognizer:swipeGR];
Related
I want to create UIView Animation like this link
css3 ripple effect example
i have tried all these codes in ViewDidLoad() and not working
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
view.backgroundColor = [UIColor blueColor];
CATransition *animation=[CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.75];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
[animation setType:#"rippleEffect"];
[animation setFillMode:kCAFillModeRemoved];
animation.endProgress=1;
[animation setRemovedOnCompletion:NO];
[view.layer addAnimation:animation forKey:nil];
[self.view addSubview:view];
i want to create the same thing in iOS .Please help me
The following lines of your code looks fine:
CATransition *animation=[CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.75];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
[animation setType:#"rippleEffect"];
[view.layer addAnimation:animation forKey:nil];
But, the problem is that your applying the animation before adding the view to its superview. which obviously will not work!
Try, to add the subview then apply the animation. I also expect that this will not work.
if you are adding this view to its superview in the viewDidLoad method. apply the animation in the ViewDidAppear or ViewWillAppear methods.
Otherwise, create a separate method that applies the animation. and call it after you add the subview by calling performSelector:withObject:afterDelay method.
Hope this helps you Sample class
UIView+Glow is a category on UIView that adds support for making views glow (useful for highlighting a part of the screen to encourage the user to interact with it).
To learn what it can be used for, and how to use it, check out the blog post
I am animating a UILabel to 'evaporate' off the screen using CATransition.
I want the label text to turn green, and move off the screen.
The following code does 'evaporate' the label fine, but doesn't change its colour before animating:
CATransition *transition = [CATransition animation];
transition.beginTime = CACurrentMediaTime();
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[self.displayLabel.layer addAnimation:transition forKey:#"evaporate"];
self.displayLabel.textColor = [self greenColor];
self.displayLabel.text = #" ";
Calling setNeedsDisplay on the label doesn't work.
Can't use a CABasicAnimation because the label text is changing.
What am I doing wrong and how do I fix it?
You basically want nested animations or, in a sense, looking for a completion block type thing.
The closest I can think of achieving this is by using the CATransition delegate
Example:
-(IBAction)btnTest:(UIButton *)sender
{
//[1] Animate text color change
CATransition *animation = [CATransition animation];
[animation setDelegate:self]; //important
[animation setRemovedOnCompletion:YES]; //better to remove the animation
[animation setBeginTime:CACurrentMediaTime()]; //not really needed
[animation setDuration:0.4];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[animation setType:kCATransitionFade];
//you can specify any key name or keep it nil. doesn't make a difference
[self.displayLabel.layer addAnimation:animation forKey:#"changeTextColor"];
[self.displayLabel setTextColor:[UIColor greenColor]];
}
#pragma mark - CATransition Delegate
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
//[2] Animate text sublayer
/*
The following CATransition should not set a delegate
otherwise this animation will loop continously
*/
CATransition *animation = [CATransition animation];
[animation setRemovedOnCompletion:YES]; //better to remove the animation
[animation setBeginTime:CACurrentMediaTime()]; //not really needed
[animation setDuration:0.4];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromTop];
//you can specify any key name or keep it nil. doesn't make a difference
[self.displayLabel.layer addAnimation:animation forKey:#"changeText"];
[self.displayLabel setText:#" "];
}
How can I get the following animation to work in blocks?
(I need the keyboard to dissappear in the completion handler of the transition animation)
- (void) showNewViewAnimatedSlideAscending:(BOOL)isAscending {
UIView * oldView = self.myView;
UIView * newView = self.myView;
UIView * superView = self.myView.superview;
[oldView removeFromSuperview];
[superView addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
if(isAscending) {
[animation setSubtype:kCATransitionFromRight];
} else {
[animation setSubtype:kCATransitionFromLeft];
}
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[superView layer] addAnimation:animation forKey:#"myTransitionAnimation"];
if(self.keyboardVisible) {
[self.view endEditing:YES];
}
}
p.s; I know, I'm removing and showing the same view. This view has received new data just before calling this method. Somehow the view displays correctly and only shows the new data in the 'new' view.
I want to animate the view in ipad like a book, view should be turned like a page from right to left and vice versa. Can anyone provide me any tutorial or example for this.
Thanks in advance.
You want to use the UIPageViewController
See e.g. this tutorial
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0f];
animation.startProgress = 0.2;
animation.endProgress = 1;
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
[animation setType:#"pageCurl"];
[animation setSubtype:kCATransitionFromLeft];
[animation setFillMode: kCAFillModeBackwards];
[self.view.layer addAnimation:animation forKey:#"animation"];
for flipping the other way you make :
[animation setType:#"pageUnCurl"];
Hope this helps, good luck :)
check link
UIPageViewController
There are another custom UIViewController transition than the 4 natives iOS:
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
Any tips?
You could also try CATransition, for example, the code below shows a transition where a second view pushes your current view out to the right. (Assuming this code is placed in your main view controller).
UIView *appWindow = [self.view superview];
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[appWindow addSubview:yourSecondViewController.view];
[self.view removeFromSuperview];
[[appWindow layer] addAnimation:animation forKey:#"showSecondViewController"];