Bouncing animation while changing view frame - ios

Add bouncing animation while changing UIVIew frame. I only know how to change frame but I don't know how to set bouncing effect while changing view frame. Below is my code....
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
CGRect frame = viewContent.frame;
frame.size.height = CGRectGetHeight(viewContentFullDetail);
viewContent.frame = frame;
} completion:^(BOOL finished) { }];
You can check animated gif image on below link. I want to add animation not same like this but near to this. Main animation are unfolding and bouncing effect.
https://drive.google.com/open?id=0B9k_Shyb5v62eFdxWXhYeXV3a0E
Please help. I don't know how to do this.

You need to try this
int duration, damping, velocity;
[UIView animateWithDuration:duration delay:0
usingSpringWithDamping:damping initialSpringVelocity:velocity
options:0 animations:^{
// your animation code here
} completion:nil];
Play with the damping and velocity values to know more about this feature in the animation code.
here is the link for a tutorial

Related

iOS how to animate view scaling from the center of the view?

I'm using an affine transform within a repeating/reversing animation to create a "pulsing" effect. However, I noticed that the button gets shifted right when the animation begins. The anchor point for the button is at (0.5,0.5):
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionRepeat|
UIViewAnimationOptionAutoreverse|
UIViewAnimationOptionAllowUserInteraction|
UIViewAnimationCurveEaseInOut
animations:^{
self.recordButton.transform = CGAffineTransformMakeScale(1.2, 1.2);
} completion:^(BOOL finished) {
}];
It appears that when the transform is applied, the origin of the button's frame stays at the same spot.
How can I animate scale transform so the center of the button remains in the same spot once the transform is applied?
I usually play with the frame and CGRect utility functions
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionRepeat|
UIViewAnimationOptionAutoreverse|
UIViewAnimationOptionAllowUserInteraction|
UIViewAnimationCurveEaseInOut
animations:^{
self.recordButton.frame = CGRectInset(self.recordButton.frame, -1.2, -1.2);
} completion:^(BOOL finished) {
}];

How to animate UISearchbar frame change keeping the rounded caps?

I would like to animate the frame change of the UISearchbar. I would like it to expand and collapse when tapped on a search button.
Am using UIViewAnimationBlock to animate
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
//Set the frame you want to the search bar
}
completion:^(BOOL finished) {
}];
I have to expand the frame from zero and collapse it back. But while animating, the search bar loses its rounded edges and becomes a rectangle. Here is a screenshot of it while still animating
Well it doesn't look good.. I want it to keep its rounded edges while expanding or collapsing. Is it possible ? If yes how ?
Any help would be much appreciated.
You can not change height of a UISearchBar try setting frames with height of 44px.
And if you want to change height then use CGAffineTransformMakeScale like..
//FOR EXPAND USE THIS:
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
self.searchBar.transform = CGAffineTransformMakeScale(1.0, 1.0);
}
completion:^(BOOL finished) {
}];
and
//FOR EXPAND USE THIS:
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
self.searchBar.transform = CGAffineTransformMakeScale(0.001, 0.001);
}
completion:^(BOOL finished) {
}];

ImageView Animation Repeatition

I am working on an application which needs animations with imageView.
At starting the position of image is at CGPoint(735,112),on clicking the animation button it has to move to the left of the screen ie to point CGPoint(20,112) and hast to repeat the animation from left to right i.e to point CGPoint(735,112),has to stop after this. i am using the following Code.
CGRect newRect=cleanStrip.frame;
[UIView beginAnimations:#"animation1" context:nil];
[UIView setAnimationDuration:3.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatAutoreverses:YES];
newRect.origin.x=20;
cleanStrip.frame=newRect;
[UIView commitAnimations];
After repeating the animation the image view has to stop at it original position CGPoint(735,112).But the above code stops the image at CGPoint(20,112).
How can i stop the image at its original position after animation.
Thanks,
you can use block to start your animation
__block CGRect newRect=cleanStrip.frame;
__block int originx = newRect.origin.x;
[UIView animateWithDuration:2.0
animations:^{
newRect.origin.x=20;
cleanStrip.frame=newRect;
}
completion:^(BOOL finished){
[UIView animateWithDuration:2.0
animations:^{
newRect.origin.x=originx ;
cleanStrip.frame=newRect;
}];
}];

UILabel always animates to same spot

I have a UILabel called "nameLabel" and I have it inside an animation block so that this happens:
_nameLabel.alpha = 1;
CGAffineTransform translate = CGAffineTransformMakeTranslation(50, 50);
_nameLabel.transform = translate;
I thought that animates the UILabel to the spot I specify but it just animates from the above spot to the place where I have it in the Interface Builder. Any help here?
Can you post the animation block and other associated code? I am not sure what CGAffineTransformMakeTranslation does with the label, but if you want to animate the frame location, you can use this:
CGRect frame = _nameLabel.frame;
frame.origin.y = 100; //Desired height, origin.x can be modified as well.
//You can also change the frame size here but it wont work on UILabels, you will need `CGAffineTransformScale` for that.
[UIView animateWithDuration: 1.5
delay:0.0
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^ {
[_nameLabel setFrame:frame];
}
completion:^ (BOOL finished) {
}];
Edit: The other way:
CGRect frame = _nameLabel.frame;
frame.origin.y = 100;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[_nameLabel setFrame: newFrame];
[UIView commitAnimations];
Current state is probably the current location of the label, try that first but if nothing happens, remove UIViewAnimationOptionBeginFromCurrentState or set the frame of the label to another location before the animation, and move it to its initial (the one in the xib file) position in the animation block, its your call.
Watch out because Autolayout cause a lot of problems.
Try to deselect 'Use Autolayout'
It solves to me all the problems trying to translate objects.

How do I get the smoothest animation possible in iOS?

I'm using the UIView method animateWithDuration:animations to animate sliding a UIView. It appears slightly choppy. Is there a better method, like CoreGraphics, to accomplish a smoother animation?
You can try to use different UIViewAnimationOptions
The default is UIViewAnimationOptionCurveEaseInOut, but you can try others:
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
v.center = CGPointMake(400, 400);
}
completion:^(BOOL finished) {
}
];

Resources