Is there any way to do things the "short and easy" way like below? The curve appears to still use EaseOut
.
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView animateWithDuration:0.5 animations:^{
// ... do stuff here
}];
Is there any way to do things the "short and easy" way like below? The curve appears to still use EaseOut
.
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView animateWithDuration:0.5 animations:^{
// ... do stuff here
}];
You are mixing two different kinds of UIView-animations. You should be using something like this either of these:
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
// ... do stuff here
} completion:NULL];
This came from the newer block-based UIView-animation API. The first line, on the other hand, is part of the older UIView animation API that looks like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
// ... do stuff here
[UIView commitAnimations];
They do the same thing and you can use either (though Apple recommends the block-based API since it is easier/cleaner to do callbacks after the animation finishes).
You can do it using Core Animation , CAKeyFrameAnimation to define the curve points. See this tutorial: http://nachbaur.com/blog/core-animation-part-4
Let's take curve points p1, p2, p3, p4 and p5, & find mid point for each pair of adjacent points. Label m1 as the mid point for p1 and p2. Similarly for m2, m3, m4.
Code:
CGFloat screenHeight = self.view.frame.size.height;
CGFloat screenWidth = self.view.frame.size.width;
UIView *aniView = [[UIView alloc] initWithFrame:CGRectMake(50, screenHeight, 50, 50)];
[aniView setBackgroundColor:[UIColor redColor]];
aniView.layer.cornerRadius = 25.0;
[self.view addSubview:aniView];
UIBezierPath *movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:aniView.center];
[movePath addQuadCurveToPoint:CGPointMake(screenWidth-50,screenHeight-50)
controlPoint:CGPointMake(screenWidth/2,screenHeight-150)];
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;
CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim, nil];
animGroup.duration = 2.0;
[CATransaction begin]; {
[CATransaction setCompletionBlock:^{
[aniView.layer removeAllAnimations];
[aniView removeFromSuperview];
}];
[aniView.layer addAnimation:animGroup forKey:nil];
} [CATransaction commit];
Copy past above code into some method and try calling the method...
© 2022 - 2024 — McMap. All rights reserved.