PDA

View Full Version : zoom animation using animation with block based methods




ashwinr87
Apr 19, 2011, 09:22 AM
Hi,

I have a zoom animation in which when I perform an action, a view comes up in a zooming fashion.

The code I use to do this is,


CGFloat xpos = self.view.frame.origin.x;
CGFloat ypos = self.view.frame.origin.y;
popContents.view.frame = CGRectMake(xpos+100,ypos+150,5,5);
[UIView beginAnimations:@"Zoom" context:NULL];
[UIView setAnimationDuration:0.8];
popContents.view.frame = CGRectMake(320, ypos-70, 350, 350);
[UIView commitAnimations];
[self.view.superview addSubview:popContents.view];

I just realized that in ios 4.0, usage in this fashion is not recommended and animations using block based methods is recommended..

I tried looking for any sort of example which would give me a hint to get the zooming effect I need using the block based methods but I have not been able to find any...

It would be great if anyone could help me out in this...



Sykte
Apr 19, 2011, 11:50 AM
Something like this should work. You may need to tweak the UIViewAnimationOptions.


[UIView animateWithDuration:0.8 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction animations:^(void) {
popContents.view.frame = CGRectMake(320, ypos-70, 350, 350);
} completion:^(BOOL finished) {
[self.view.superview addSubview:popContents.view];
}];


Don't forget you can nest animations inside of each other.

ashwinr87
Apr 19, 2011, 11:57 AM
Thank you.. I also figured out the same thing some time back but forgot to post it here...

I would like to ask another thing.. whatever value I give in the options: does not seem to have any effect on my animations.. say If i had given[UIView animateWithDuration:0.8 delay:0.0 options: UIViewAnimationTransitionFlipFromLeft animations:^ { popContents.view.frame = CGRectMake(160, 70, 350, 350);
[self.view.superview bringSubviewToFront:self.view];
[self.view.superview addSubview:popContents.view]; }
completion: ^(BOOL finished) {
NSLog(@"DONE");
}
]; I thought by adding options:UIViewAnimationTransitionFlipFromLeft , it should have added an extra effect to my animation in addition to the zooming effect..

would you be able to help me out?

Something like this should work. You may need to tweak the UIViewAnimationOptions.


[UIView animateWithDuration:0.8 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction animations:^(void) {
popContents.view.frame = CGRectMake(320, ypos-70, 350, 350);
} completion:^(BOOL finished) {
[self.view.superview addSubview:popContents.view];
}];


Don't forget you can nest animations inside of each other.

Sykte
Apr 19, 2011, 05:22 PM
[UIView animateWithDuration:0.8 delay:0.0 options: UIViewAnimationTransitionFlipFromLeft animations:^ { popContents.view.frame = CGRectMake(160, 70, 350, 350);
[self.view.superview bringSubviewToFront:self.view];
[self.view.superview addSubview:popContents.view]; }
completion: ^(BOOL finished) {
NSLog(@"DONE");
}
];

UIViewAnimationTransitionFlipFromLeft

This isn't a UIViewAnimationOption, what happens when you sub in the following.


UIViewAnimationOptionTransitionFlipFromLeft

ashwinr87
Apr 20, 2011, 09:24 AM
Thanks for the reply...

here is the edited code...

[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^
{
popContents.view.frame = CGRectMake(160, 70, 350, 350);
[self.view.superview bringSubviewToFront:self.view];
[self.view.superview addSubview:popContents.view];
}
completion: ^(BOOL finished)
{
NSLog(@"DONE");
}];

so what happens here is that the table view rotates while the popContents view zooms to position.. I understand that is what will happen since I had given transitionWithView:self.view .. however, how will I be able to add this effect to the popContents view ( the view which zooms to position)... is it possible? I tried transitionWithView:popContents.view but that does not seem to have any effect...

[UIView animateWithDuration:0.8 delay:0.0 options: UIViewAnimationTransitionFlipFromLeft animations:^ { popContents.view.frame = CGRectMake(160, 70, 350, 350);
[self.view.superview bringSubviewToFront:self.view];
[self.view.superview addSubview:popContents.view]; }
completion: ^(BOOL finished) {
NSLog(@"DONE");
}
];

UIViewAnimationTransitionFlipFromLeft

This isn't a UIViewAnimationOption, what happens when you sub in the following.


UIViewAnimationOptionTransitionFlipFromLeft