zoom animation using animation with block based methods

Discussion in 'iOS Programming' started by ashwinr87, Apr 19, 2011.

  1. macrumors member

    Joined:
    Mar 9, 2011
    #1
    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...
     
  2. macrumors regular

    Joined:
    Aug 26, 2010
    #2
    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.
     
  3. thread starter macrumors member

    Joined:
    Mar 9, 2011
    #3
    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?

     
  4. macrumors regular

    Joined:
    Aug 26, 2010
    #4
    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
    
     
  5. ashwinr87, Apr 20, 2011
    Last edited: Apr 20, 2011

    thread starter macrumors member

    Joined:
    Mar 9, 2011
    #5
    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...

     

Share This Page