Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create UIView ripple circle animation?

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

like image 818
naveen kumar Avatar asked Jul 28 '15 15:07

naveen kumar


1 Answers

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.

like image 66
hasan Avatar answered Oct 17 '22 23:10

hasan