简体   繁体   English

UIView动画不允许居中设置

[英]UIView animation does not allow center setting

I try to move an ImageView (say, view1) so that its center matches another ImageView's center (view2), while resizing it. 我尝试移动ImageView(例如view1),以使其中心与另一个ImageView的中心(view2)匹配,同时调整其大小。 On completion this first view is removed, but is image is copied into the view2, so its image seems to remain. 完成后,将删除第一个视图,但是将图像复制到view2中,因此似乎保留了它的图像。 For that purpose I tried many combinations but with any, even creating a new ImageView3 that I can insert into view2, as soon as I try to set the center of view3 to match the center of view2, nothing happens and my image disappears, never being inserted in view2. 为此,我尝试了许多组合,但尝试了多种组合,甚至创建了一个新的ImageView3并可以将其插入到view2中,一旦我尝试将view3的中心设置为与view2的中心匹配,则什么也没有发生,并且我的图像消失了,插入view2。 Without setting the center, everything works. 无需设置中心,一切正常。 Damn, Why? 该死,为什么? Did I miss something obvious or am I stupid? 我错过了明显的事情还是我很愚蠢? Or should I definitely use coreAnimation? 还是我绝对应该使用coreAnimation?

[UIView animateWithDuration:0.5 animations:^{
    view1.center = view2.center;
    view3.center = view2.center;
} completion:^(BOOL finished){
    [view2 addSubview:view3];
}]; 

In the completion block, you add view3 as a subview to view2. 在完成块中,将view3作为子视图添加到view2。 This is probably not what you want, at least not without further adjusting its position. 这可能不是您想要的,至少在没有进一步调整其位置的情况下也是如此。 Since you have reset its center in the animation, the coordinates are based on the parent view. 由于您已在动画中重置了其中心,因此坐标基于父视图。 When you add it to view2, the apparent position shifts based on the relative position of view2. 当您将其添加到view2时,视在位置会根据view2的相对位置移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM