Reimplement UIView block based animation methods with custom easing curve

后端 未结 2 1950
时光说笑
时光说笑 2021-02-10 16:08

The lack of custom easing curves in UIView\'s block based animation methods leads to Core Animation if more advanced curves are needed.

A way of doing this with a Categ

2条回答
  •  孤街浪徒
    2021-02-10 16:54

    I don't know how Apple implements their block based methods, but reading BlocksKit sourcecode, I understood that to implement the method you mentioned, you probably need to:

    1. Declare a UIView category such as UIView (block)
    2. In the category, add a NSTimer property to fire/invalidate the timer with given duration
    3. In the category, add a block property to keep the easingCurveFunction block code
    4. In the category, add another block perty to keep the animation block code
    5. In your block-based method, set the timer, save the blocks code to properties
    6. When the timer fires, run the easingCurveFunction block and animation block, as you keep them in the properties

    I actually followed this practice when adding my own block-based methods to Apple's classes.

提交回复
热议问题