views:

94

answers:

1

I have a few XIBs that are my pages, and i'm using presentmodalviewcontroller to switch between them with some buttons. Now I want to use other buttons to pull up overlays on those views. How I have it now is I have a button which simply toggles the "Hidden" property on the UIImageview.

What are options for animating the show/hide functionality of this? I'd like some sort of zoom-in or zoom-out effect when the overlay is called up rather than just suddenly showing/hiding.

-(IBAction)basketballbutton{
if (basketball.hidden == YES)
    basketball.hidden = NO;
else if (basketball.hidden == NO)
    basketball.hidden = YES;

Thanks!

+1  A: 

You can animate the view opacity using the alpha property.

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
[basketball setAlpha:([basketball alpha] > 0.0) ? 0.0f : 1.0f];
[UIView commitAnimations];

This will animate the showing and hiding of the view.

Here is how you set the transform for scaling:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
// Scale up 2x
[basketball setTransform:CGAffineTransformMakeScale(2.0f, 2.0f)];
[UIView commitAnimations];
Matt Long
Thanks, that's much better. How about scale? Is there a similar method to animate the scale of the image?
Hippocrates
Yes. Look at setting the transform on the view--specifically you need to set the scale transform using CGAffineTransformMakeScale (http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html#//apple_ref/c/func/CGAffineTransformMakeScale)
Matt Long
I updated my answer with some code to show the scale transform.
Matt Long