gpt4 book ai didi

iphone - 获取 UIView 框架缩放动画

转载 作者:可可西里 更新时间:2023-11-01 06:25:36 26 4
gpt4 key购买 nike

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

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

View 从一个小框架 (centerParent.x, centerParent.y,20, 20) 开始,然后变为 (centerParent.x, centerParent.y,300, 300)。

但是当我改变框架时,我必须从 View 的位置 (0.0) 开始改变它,而不是因为它的中心点。有谁知道怎么做吗?

谢谢

最佳答案

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

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

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

关于iphone - 获取 UIView 框架缩放动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11261618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com