我想要添加一个UIView,并使用缩放动画效果,就像这样:
^
|
<---.--->
|
v
这个视图从一个小框架(centerParent.x,centerParent.y,20,20)开始,然后变成(centerParent.x,centerParent.y,300,300)。
但是当我改变框架时,我必须从视图的位置(0.0)开始改变,而不是从它的中心点开始。有人知道如何做吗?
谢谢
我想要添加一个UIView,并使用缩放动画效果,就像这样:
^
|
<---.--->
|
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;
}];
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);
}];
- (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];