How to create UIView ripple circle animation? - ios

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

Related

Swipe Transition Animation for Webview

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];

UIView slide animation using blocks instead?

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.

How can we animate the ipad view like a book

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

iOS: Animating Incorrect Orientation at rootViewController?

Context: I am trying to perform a custom animation from a normal UIViewController.view to a UISplitViewController.view. The animation should show from Left to Right.
I set self.window.rootViewController = viewController where viewController is a normal UIViewController.
Once the user swipe, the following gets called:
UIView *theWindow = [viewController.view superview];
[viewController.view removeFromSuperview];
[theWindow addSubview:self.splitViewController.view];
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:#"SwitchToView1"];
When the device is in a portrait mode, everything went perfectly. However, when the device is in the landscape mode, the transition animation performs as if the device is still in the portrait mode. For example: Instead of coming in from the left, it comes in from the bottom. The orientation of both the views are completely correct. Only the transition is weird.
So, I've been playing around with your code (I did a best-guess reconstruction of how you have your project set up), and I was able to get the desired effect with the following code. I tried setting the frames and bounds of layers, of views, or sublayers, etc., and none of that worked. CATransform3D's, CATransform3DRotates, etc also weren't doing the trick. I also Googled for a solid hour. Either no one has had your issue, or no one has solved your issue. Regardless, this solution works, and unless some Core Animation guru can provide a better solution, you're welcome to this:
- (void)swipeGesture:(UISwipeGestureRecognizer *)sender {
UIView *theWindow = [self.viewController.view superview];
UIInterfaceOrientation interfaceOrientation = self.viewController.interfaceOrientation;
NSString *subtypeDirection;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
subtypeDirection = kCATransitionFromTop;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
subtypeDirection = kCATransitionFromBottom;
}
else {
subtypeDirection = kCATransitionFromLeft;
}
[self.viewController.view removeFromSuperview];
[theWindow addSubview:self.splitViewController.view];
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:subtypeDirection];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:#"SwitchToView1"];
}

Custom UIViewController Transition?

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"];

Resources