Ankit Sachan
Ankit Sachan

Reputation: 7840

ipad: present a view with zoom out effect and remove with zoom in effect

I want to display a view with zoom out effect on click of a button and dissolve the view with a zoom in effect can you guide me to achieve this.

Thanx in advance

Upvotes: 3

Views: 1425

Answers (1)

DarkDust
DarkDust

Reputation: 92336

You can do it with a CAAnimation to the view's layer:

CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
[ani setDuration:0.5];
[ani setRepeatCount:1];
[ani setFromValue:[NSNumber numberWithFloat:1.0]];
[ani setToValue:[NSNumber numberWithFloat:0.1]];
[ani setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[myView layer] addAnimation:ani forKey:@"zoom"];

This adds an animation that makes the view shrink into its center. You might want to add set a delegate and implement animationDidStop:finished: in which you then hide the view and reset the layer's scale (see CAAnimation reference).

To create the opposite effect simply exchange the from and to values.

Also note that while the scale is not 1.0, the frame property is undefined. That is, if you try to move it or change its size while the layer's scale is not 1.0, strange things will happen.

Upvotes: 5

Related Questions