得到一个UIView框架的缩放animation

我想添加一个UIView的过渡样式缩放animation像这样:

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

该视图从一个小框架(centerParent.x,centerParent.y,20,20)开始,然后更改为(centerParent.x,centerParent.y,300,300)。

但是当我改变框架时,我必须从视图的位置(0.0)开始改变它,而不是它的中心点。 有谁知道如何做到这一点?

谢谢

使用当前使用的方法(不使用变换,而只是调整视图的大小),只需要重置视图的原点或中心。 最简单的是中心:

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

你也可以通过移动从x和y减去1/2的大小变化的差异来重置原点,但是这是更多的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); }]; 

为了使视图缩小,保持自己的中心很容易,但你需要使用变换。 这里是一个代码。 只需添加并连接一个视图,将其命名为zoomerView。

在这个例子中,我只是把这个添加到主视图触动结束。

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint center = zoomerView.center; [UIView animateWithDuration:1 animations:^{ zoomerView.transform = CGAffineTransformScale(zoomerView.transform, 1.2, 1.2); }]; } 

希望这可以帮助你

尝试这个

 [UIView animateWithDuration:secs delay:1.0 options:option animations:^{ yourview.transform = CGAffineTransformScale(view.transform, 100.0, 100.0); } completion:nil];