开发者

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, 开发者_如何学Goview.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.


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);
}];


Try the code given by @Deepak Danduprolu and also don't forgot to UnCheck the "Use AutoLayout" checkbox in the show file inspector window of the storyboard. It works for me.


Just offset the X,Y position of the view. Lets say you're DECREASING both the width and height of the frame by 20 points: you should then ADD 10 points to both the X and Y position of the frame.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜