I have a translate animation, moving my button from A to B.
That route looks like this:
1) Button slowly accelerates
2) At the middle of animation gets to the peak of it's speed
3) Slows down as it approaches the end
This is my code
[UIView animateWithDuration:speed
delay:delay
options:UIViewAnimationOptionAllowUserInteraction
animations:^(void){
[UIView setAnimationRepeatCount:5];
cloud.frame = (CGRectMake(cloud.frame.origin.x,
cloud.frame.origin.y+900, cloud.frame.size.width, cloud.frame.size.height));
}completion:nil];
I want my animation to have a same speed all the time.
How can I achieve this?
Add the UIViewAnimationOptionCurveLinear to your animation options, like this:
[UIView animateWithDuration:speed
delay:delay
options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveLinear
animations:^(void){
[UIView setAnimationRepeatCount:5];
cloud.frame = (CGRectMake(cloud.frame.origin.x,
cloud.frame.origin.y+900, cloud.frame.size.width, cloud.frame.size.height));
}completion:nil];
I think you wanna try setting the "option" parameter to:
UIViewAnimationOptionCurveLinear
Related
When a user makes a flick gesture on a UIScrollView, the UIScrollView gets a momentum and starts moving, then slow down and finally stop.
But how can I make this happen programmatically? I mean without a finger flicking, the UIScrollView just start moving automatically and then slow down to a speed of 0.
In my app I have made my UIScrollView unlike a normal UIScrollView (say it looks like a roller), so I want make a hint to the user that he can scroll it (and then everything get started!)
I have googled a lot but there seemed no way to solve my problem. The setContentOffset just couldn't make the natural "slow down and stop at somewhere ahead" effect.
Any idea would be appreciated.
Thanks in advance.
Try, something like this >
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:.8];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:(abs(1-3)*0.3)];
self.myScroll.contentOffset = CGPointMake(0, 500);
[UIView commitAnimations];
It is not currently what you need, but you can customise this code, and may be all be ok)
or use this code>
[UIView animateWithDuration:2.
delay:0.3
usingSpringWithDamping:1.
initialSpringVelocity:7.
options:UIViewAnimationOptionCurveEaseInOut animations:^{
//Animations
self.myScroll.contentOffset = CGPointMake(0, 500);
}
completion:^(BOOL finished) {
//Completion Block
}];
I think it is like you want(animation with damping like swipe effect)
So I want to do a UI animation where a view gradually fades out. Right now I have something like this
[UIView animateWithDuration:2.0f
animations:^{
myView.alpha = 0.0f;
}
];
So right now over the course of those 2 seconds, the view will linearly gradually fade out. However I want to make it so that the fade out is non-linear. For instance, I want it to start fading out slowly and then fade more quickly over time.
How would I do this?
Use one of the longer forms of animateWithDuration methods that take an options parameter, like animateWithDuration:delay:options:animations:completion:.
One of the options you can supply is a timing curve like UIViewAnimationOptionCurveEaseInOut.
Your choices are
UIViewAnimationOptionCurveEaseInOut = 0 << 16,
UIViewAnimationOptionCurveEaseIn = 1 << 16,
UIViewAnimationOptionCurveEaseOut = 2 << 16,
UIViewAnimationOptionCurveLinear = 3 << 16,
If you use CAAnimation instead of UIView animation, you can also create your own custom timing function using the control points of a bezier curve that describes the desired timing function. However, CAAnimation is more complex to use and less well documented.
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
myView.alpha = 0.0f;
} completion:nil];
Or pick your favorite time curve instead of UIViewAnimationOptionCurveEaseInOut
You must be needing about "ease in" timing curve in which the animation starts slowly and ends as linear. Try the below code,
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
myView.alpha = 0.0f;
} completion:nil];
Please do let me know, if it solves your problem.
Is there anyway to stop a UIView animation, but not jump to the end values?
I'd like to continue from where I am, instead of having a jerky looking 'snap' before it starts moving to it's new position
Here's the answer for other people who stumble here. Quite simple really, just pass 'options:UIViewAnimationOptionBeginFromCurrentState' into the options, and it will resume from it's current locaiton
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.scrollView.contentOffset = CGPointMake(visibleFrame.origin.x, visibleFrame.origin.y);
}
completion:^(BOOL finished){}
];
I have UIScrollView which can zoom an UIView. One time I want to zoom out to the default state.
Here is my code.
[UIView animateWithDuration:0.3
animations:^{
[scroll zoomToRect:self.view.bounds animated:NO];
} completion:nil];
Wow. It jumps like hell. Seems like it sets zoomScale = 1 and then animating the frame.
I'll add a line.
[UIView animateWithDuration:0.3
delay:0 options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[scroll zoomToRect:self.view.bounds animated:NO];
} completion:nil];
Works just fine. So how UIViewAnimationOptionBeginFromCurrentState helps in this case? From help I know
Start the animation from the current setting associated with an already in-flight animation.
But there is NO in-flight animations.
I found answer, it looks expedient but work fine.
write animation code in other place use method like 'performSelector:'
then it recognize correct current state
I've made something like:
[UIView animateWithDuration:2.0
delay:0
options:UIViewAnimationOptionRepeat
animations:^{
NSLog(#"Repeating...");
/** code **/
}
completion:^(BOOL finished) {
/** code **/
}];
But the animation does not repeat itself.
Am I missing something?
I've removed the color animation, but the animation doesn't repeat yet. But I must be doing something really wrong, 'cause I tried the following simple code and the animation still doesn't repeat:
[UIView animateWithDuration:1.0f
delay:0
options: UIViewAnimationOptionRepeat
animations:^{
NSLog(#"Repeating...");
self.alpha = 1;
}
completion:nil];
Depending on the animation (still would like to see your code) you might have to reverse your animation in order for it to repeat. For example, if your animation changes an alpha value from 0 to 1, repeating that, without reversing the alpha back to 0, isn't going to do much. You may need to add UIViewAnimationOptionAutoreverse to your animation options.