Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get to an UIView frame a zoom animation

I am trying to add one UIView with a transition style zoom animation like this:

     ^
     |
 <---.--->
     |
     v

The view start with a little frame (centerParent.x, centerParent.y,20, 20) and then change to (centerParent.x, centerParent.y,300, 300).

But when I change the frame I have to change it since the postion (0.0) of the view, not for it's center point. Does anyone know how to do it?

Thanks

like image 583
damacri86 Avatar asked Nov 22 '25 13:11

damacri86


1 Answers

With the methodology you're currently using (not using a transform but simply resizing the view) you just need to reset the origin or center of the view). The easiest is the center:

 view.frame = CGRectMake(0, 0, 20, 20);
    CGPoint center = view.center;
    [UIView animateWithDuration: 1.0f animations:^{
        view.frame = CGRectMake(0, 0, 300, 300);
        view.center = center;
    }];

You can also reset the origin by moving subtracting 1/2 the difference of the size change from the x and y, but this is more math:

view.frame = CGRectMake(0, 0, 20, 20);
    CGPoint origin = view.frame.origin.
    [UIView animateWithDuration: 1.0f animations:^{
        origin.x -= (300 - 20) / 2;
        origin.y -= (300 - 20) / 2;
        view.frame = CGRectMake(origin.x, origin.y, 300, 300);
    }];
like image 149
Aaron Hayman Avatar answered Nov 25 '25 06:11

Aaron Hayman