Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate size of a UIView around center point

I have a UIView which I want to grow from it's center when a user touches it. The problem is that when animating it the view expands left and then moves to the right, whereas I want it to expand to the left and right, while keeping the center point the same.

This is the code I have at the moment:

[UIView animateWithDuration:1 animations:^(void) {
    [view setFrame:CGRectMake(-10, 0, 320, view.frame.size.height)];
}];

I didn't think it was going to be difficult to do this, but it seems it is. Short of animating it manually with a timer I have no idea how to get it to expand from it's center.

like image 754
Jonathan. Avatar asked Jun 21 '11 18:06

Jonathan.


1 Answers

I am not quite sure why it's working for you in a weird manner. Did you alter the anchorPoint property in any way? Otherwise it should grow from center.

Does doing

CGRect newFrame;
newFrame = CGRectInset(view.frame, -10, -30);

[UIView animateWithDuration:1 animations:^(void) {
    view.frame = newFrame;
}];

also give you the same result? What about this?

[UIView animateWithDuration:1 animations:^(void) {
    view.transform = CGAffineTransformScale(view.transform, 1.1, 1.1);
}];
like image 163
Deepak Danduprolu Avatar answered Nov 05 '22 07:11

Deepak Danduprolu