I'm trying to rearrange the content of my UIView based on a user event (rotation), and I've found that I would like to combine a translation animation, and the fading out and fading in of various controls.
Since this seems to depend on the "options" of the animate functions, I assumed that I need to launch two animations concurrently with different options, as follows. The "Layout_Set" function assigns new "frames" to all of my controls, which works fine. The "setHidden" in the block of the other animation is intended to fade out a single control on rotation.
However... doesn't work. Is this the right way to (a) launch concurrent animations and (b) to fade out a control?
Thanks very much for any help.
[UIView animateWithDuration:duration
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn +
UIViewAnimationOptionCurveEaseOut + UIViewAnimationOptionBeginFromCurrentState
animations:^{
[self Layout_Set];
}
completion:^(BOOL finished){}];
[UIView animateWithDuration:duration
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn +
UIViewAnimationOptionCurveEaseOut + UIViewAnimationOptionBeginFromCurrentState
animations:^{
[self.UIImageQRCameraLogo setHidden:true];
}
completion:^(BOOL finished){}];
Related
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.
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
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.
I am moving a UIImageView with the following animation:
[UIView animateWithDuration:.5 delay:0 options:(UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
myImage.frame = CGRectOffset(myImage.frame, myImageOffset.x, myImageOffset.y);
}
completion:^(BOOL finished){
}
];
The problem is the image starts moving slow, then speeds up and slows down again before ending the animation. Isn't the UIViewAnimationCurveLinear option supposed to make the animation perform at a constant rate?
Try using this option instead - UIViewAnimationOptionCurveLinear. I found it while looking at this question on another site - http://www.iphonedevsdk.com/forum/iphone-sdk-development/89009-block-animation-ignores-uiviewanimationcurvelinear.html
I have this code:
successview is my view and it start with alpha 0.00 but when it finish the animation with autoreverse, successview become with alpha 1.00...why?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationRepeatAutoreverses:YES];
[successView setAlpha:1.00];
[UIView commitAnimations];
One approach is to do two different animations: One that progresses towards an alpha value of 1.0 and then another that goes from 1.0 back to 0.
Use the animateWithDuration:animations:completion: method of the UIView to accomplish this. You can do the reverse in the completion block.
Something along the lines of:
[UIView animateWithDuration:0.2
animations:^{view.alpha = 1.0;}
completion:^(BOOL finished){
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0;}];
}];
See UIView documentation for more details on animations.
It's in the docs:
If you combine autoreversing with a repeat count (settable using the setAnimationRepeatCount: method), you can create animations that shift back and forth between the old and new values a specified number of times. However, remember that the repeat count indicates the number of complete cycles. If you specify a whole number such as 2.0, the animation ends on the old value, which is followed by the view immediately updating itself to show the new value, which might be jarring. If you want the animation to end on the new value (instead of the old value), add 0.5 to the repeat count value. This adds an extra half cycle to the animation.
Update: read wrong your code, but docs suggest that you use animateWithDuration:delay:options:animations:completion: instead if you are targeting iOS 4.0 and later.
If someone is interested, here's Swift code:
UIView.animate(withDuration: 0.2, animations: {
view.alpha = 1
}) { (finished) in
UIView.animate(withDuration: 0.2, animations: {
view.alpha = 0
})
}