围绕中心点的UIView的动画大小

Jon*_*an. 8 iphone animation objective-c uiview

我有一个UIView,当用户触摸它时我想从它的中心发展.问题在于,当动画制作时,视图向左展开然后向右移动,而我希望它向左和向右扩展,同时保持中心点相同.

这是我目前的代码:

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

我认为这样做并不困难,但似乎确实如此.如果没有使用计时器手动设置动画,我不知道如何从它的中心扩展它.

Dee*_*olu 9

我不太确定为什么它以奇怪的方式为你工作.你有没有改变anchorPoint房产?否则它应该从中心发展.

做的

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

[UIView animateWithDuration:1 animations:^(void) {
    view.frame = newFrame;
}];
Run Code Online (Sandbox Code Playgroud)

还能给你相同的结果吗?那这个呢?

[UIView animateWithDuration:1 animations:^(void) {
    view.transform = CGAffineTransformScale(view.transform, 1.1, 1.1);
}];
Run Code Online (Sandbox Code Playgroud)