得到UIView框架的缩放动画 [英] get to an UIView frame a zoom animation

查看:93
本文介绍了得到UIView框架的缩放动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个带有过渡样式缩放动画的UIView,如下所示:

I am trying to add one UIView with a transition style zoom animation like this:

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

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

The view start with a little frame (centerParent.x, centerParent.y,20, 20) and then change to (centerParent.x, centerParent.y,300, 300).

但是当我改变帧时,我必须改变它,因为视图的位置(0.0),而不是它的中心点。有谁知道怎么做?

But when I change the frame I have to change it since the postion (0.0) of the view, not for it's center point. Does anyone know how to do it?

谢谢

推荐答案

随着您当前正在使用的方法(不使用转换,只需调整视图大小),您只需重置视图的原点或中心即可。最简单的是中心:

With the methodology you're currently using (not using a transform but simply resizing the view) you just need to reset the origin or center of the view). The easiest is the center:

 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减去1/2大小变化的差异来重置原点和y,但这是更多的数学:

You can also reset the origin by moving subtracting 1/2 the difference of the size change from the x and y, but this is more 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);
    }];

这篇关于得到UIView框架的缩放动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆