简体   繁体   中英

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. On completion this first view is removed, but is image is copied into the view2, so its image seems to remain. 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. Without setting the center, everything works. Damn, Why? Did I miss something obvious or am I stupid? Or should I definitely use 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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