View Controller Transition animate subview position

后端 未结 2 915
梦如初夏
梦如初夏 2021-02-09 18:33

I\'m trying to create a simple transition animation between two view controllers, both of which have the same label. I simply want to animate the label from its position in the

2条回答
  •  悲哀的现实
    2021-02-09 18:43

    The problem lies in dealing with coordinate systems. Consider these numbers:

    fromViewController.label.frame: {{115.5, 313}, {144, 41}}
    toViewController.titleLabel.frame: {{16, 12}, {144, 41}}
    

    Those pairs of numbers are unrelated:

    • The frame of the label is in the bounds coordinates of its superview, probably fromViewController.view.

    • The frame of the titleLabel is in the bounds coordinates of its superview, probably toViewController.view.

    Moreover, in most custom view transitions, the two view controller's views are in motion throughout the process. This makes it very difficult to say where the intermediate view should be at any moment in terms of either of them.

    Thus you need to express the motion of this view in some common coordinate system, higher than either of those. That's why, in my answer here I use a snapshot view that's loose in the higher context view.

提交回复
热议问题