简体   繁体   中英

How to obtain changes to view position when animating frame?

I need to update a view continuously depending on another view's position while it's moving across the screen. I tried using KVO on frame, but it seems to trigger only at the beginning of the animation. Is there a recommended way of doing this?

您想看一下“核心动画”表示层,它应该告诉您动画期间的位置。

I would add a repeatable timer and make something like:

[self updateView:_view
   usingPosition:[_anotherView.presentationLayer position]];

(Don't you know _anotherView's animation in advance? Maybe then you can setup _view animation directly?)

Why not just set both animations for both view at the same time?

[UIImageView animateWithDuration:aDuration
                           delay:0
                         options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState
                      animations:^(void) {
                          view1.center = somePosition;
                          view2.center = someOtherPosition;
                      } completion:NULL];

They will move at the same time and with the option : UIViewAnimationOptionBeginFromCurrentState if you start an other animation before this one is finished the views will start at the point they were stopped.

But if it's not what you are looking for, can you update your question with precision on how view1 is moving.

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