UiTableview cell scaling animation - ios

Hi I am new to IOS devlopment.I need my table view cell to animate like scaling animation(i. e.whenever I scroll up, the cell size need to scale out (increase) from center position based on scrolling position and whenever I scroll down the cell size should scale in(decrease) based on scrolling position).I tried to find but I can't able to trigger out the actual solution.Can anyone help me out regarding this.Thanks for your help in advance

I tried to animate the UIImageView in UITableViewCell. This is just an idea, You can change it as per your requirement.
Write the Following code in cellForRowAtIndexPath method.
cell.animatedImageView.transform=CGAffineTransformIdentity;
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
cell.animatedImageView.transform=CGAffineTransformMakeScale(1.5, 1.5);
}
completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
cell.animatedImageView.transform=CGAffineTransformMakeScale(1, 1);
}
completion:^(BOOL finished){
cell.animatedImageView.transform=CGAffineTransformIdentity;
}];
}
}];
Let me know if you have any query.

Related

Bouncing animation while changing view frame

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

How i can do an uiimageView zoom animation linked to uiscrollview contentoffest?

I'm trying to achive an animation that zoom an imageview accordingly to a scrollview offset (i have seen something similar in spotify and some others apps). How i can do? I have tried something like:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (Scroll.contentOffset.y<-10 && Scroll.contentOffset.y>-20) {
[UIView animateWithDuration:0.1
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
ImageView.transform=CGAffineTransformMakeScale(1.1, 1.1);
}
completion:^(BOOL finished){
}];
}
if (Scroll.contentOffset.y<-20 && Scroll.contentOffset.y>-30) {
[UIView animateWithDuration:0.1
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
ImageView.transform=CGAffineTransformMakeScale(1.2, 1.2);
}
completion:^(BOOL finished){
}];
}
}
and so on until a value of 1.6 . Naturally this methods doesn't works well, it is called to many times and visually it jitters... I wanto to achive this result:
The user scroll down the scrollview while an image view placed in the background is scaled until an arbitray value (and a reverse behaviour when the user returns to scroll up). What is a correct approch?
Try setting the transform depending on the contentOffset without using animations, like
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat scale = 1;
if(Scroll.contentOffset.y<0){
scale -= Scroll.contentOffset.y/10; //calculate the scale factor as you like
}
ImageView.transform = CGAffineTransformMakeScale(scale,scale);
}

Showing UIView with bouncy animation

I want to create a bouncy animation like in the Skitch application - when i press a button, a subview (simple view with several buttons) will appear from the side and will bounce a bit until it stops.
I can't find any standard animation that does that, so how i can implement this animation?
You can try this :
// Hide your view by setting its position to outside of the bounds of the screen
// Whenever you want, call this :
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
// Set your final view position here
}
completion:^(BOOL finished) {
}];
This method is the same as the usual animateWithDuration: but it introduces a spring animation.
Use UIView method:
+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
usingSpringWithDamping:(CGFloat)dampingRatio
initialSpringVelocity:(CGFloat)velocity
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
This will do what you want
Use the UIView method, If you want bouncing effect. Then you need to nested the animation process and give the frame as needed for that view. Here's the example:
CGRect frameOnStart = CGRectMake(200,200 ,60 ,60); //On start show small view
CGRect frameOnAnimate = CGRectMake(80,80 ,150 , 150); //while animate show large view
CGRect frameAfterAnimate = CGRectMake(100,100,120 ,120); //after animate large take it back to original frame. SO it loos like bouncing animation
// Whenever you want, call this :
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
// Set your on Animate position here
view.frame = frameOnAnimate;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
// Set your final view position here
view.frame = frameAfterAnimate;
}
completion:^(BOOL finished) {
}]
}];
Thanks.

Is it posible to do multiple animations on UIView without using completion block

This is simple question just for illustrating point, my concrete code is much more complicated.
Let say that I have UILabel that is position on TOP LEFT.
With this code, I will move it to TOP RIGHT:
// labelMove is moved to TOP RIGHT
[UIView animateWithDuration:1.0f
delay:2.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
labelMove.center = CGPointMake(250.0f, 40.0f);
}
completion:nil];
If I have this code:
// labelMove is moved to TOP RIGHT
[UIView animateWithDuration:1.0f
delay:2.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
labelMove.center = CGPointMake(250.0f, 40.0f);
}
completion:nil];
// labelMove is moved to BOTTOM RIGHT
[UIView animateWithDuration:1.0f
delay:2.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
labelMove.center = CGPointMake(250.0f, 450.0f);
}
completion:nil];
It will not start from TOP LEFT, but from TOP RIGHT, and then go BOTTOM RIGHT.
Somehow first animation is not animated, only the last one.
I do not get it why, but that is not so important.
I can put second in completion: block in first and then it will work.
Like this code.
// labelMove is moved to TOP RIGHT
[UIView animateWithDuration:1.0f
delay:2.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
labelMove.center = CGPointMake(250.0f, 40.0f);
}
completion:^(BOOL finished){
// labelMove is moved to BOTTOM RIGHT
[UIView animateWithDuration:1.0f
delay:2.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
labelMove.center = CGPointMake(250.0f, 450.0f);
}
completion:nil];
}];
QUESTION
Is it posible to have effect from last code but without using completion block in any way.
That is very important for me.
I try with CABasicAnimation, but could not do it, maybe somebody with more experience can ?
I am sure that there must be some way, but I just can not figure it out.
Your code with no completion block does not work because you are attempting to animate the label to two different locations at exactly the same point in time. This is physically impossible.
When you run that second animation inside a completion block, you are running it after the first animation, instead of at the same time. To achieve the same effect, dispatch the second animation so that it is performed after the first animation. Since the first animation will take 2.0 delay + 1.0 duration = 3.0 seconds to complete, dispatch after 3.0 seconds. See below.
// labelMove is moved to TOP RIGHT
[UIView animateWithDuration:1.0f
delay:2.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
labelMove.center = CGPointMake(250.0f, 40.0f);
}
completion:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// labelMove is moved to BOTTOM RIGHT
[UIView animateWithDuration:1.0f
delay:2.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
labelMove.center = CGPointMake(250.0f, 450.0f);
}
completion:nil];
});
Just be aware that without using the completion block, you cannot insure the first animation is truly finished animating. In practice this should usually be fine.
You could use a CAKeyframeAnimation, and create a path using the two points.
Here are some examples from apple:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Animation_Types_Timing/Articles/PropertyAnimations.html

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) {
}];

Resources