Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ashwinr87

macrumors member
Original poster
Mar 9, 2011
81
0
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,

Code:
    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...
 
Something like this should work. You may need to tweak the UIViewAnimationOptions.

Code:
[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.
 
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
Code:
[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.

Code:
[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.
 
Code:
[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");
						 }
		 ];
Code:
UIViewAnimationTransitionFlipFromLeft

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

Code:
UIViewAnimationOptionTransitionFlipFromLeft
 
Thanks for the reply...

here is the edited code...

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
Code:
 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
Code:
 transitionWithView:popContents.view
but that does not seem to have any effect...

Code:
[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");
						 }
		 ];
Code:
UIViewAnimationTransitionFlipFromLeft

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

Code:
UIViewAnimationOptionTransitionFlipFromLeft
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.