How to configure UIViewAnimationCurve as a CAMediaTimingFunctionWithControlPoints function

UIViewAnimationCurve only has

  • UIViewAnimationCurveEaseInOut
  • UIViewAnimationCurveEaseIn
  • UIViewAnimationCurveEaseOut
  • UIViewAnimationCurveLinear

these functions.

but I need animation ExpoOut , BackInOut for UIView.

as ExpoOut [CAMediaTimingFunction functionWithControlPoints:0.12 :0.51 :-0.4 :1];

I used CABasicAnimation , but it cannot change the frame as a UIView animation, it is very bad when resizing the view.

or you have a better way to change the view frame as real, and not look like zoomin.

thanks.

+4
source share
3 answers

The problem is that it is not possible to define a synchronization function for animations based on UIView. As far as I can tell, you are left with a lot of unpleasant options:

  • Switch to using CALayer-based animations - with a serious problem: if the delegate is set up for presentation, the animation will not happen. Since this is required for UIViews, this is an unattractive option.
  • Add a parent layer to your views and animate this layer - with the same serious problem that this layer is nowhere in nib, and changes to nib can inadvertently break animations.
  • Do not use the custom sync function.

I hacked my way by setting the delegate to zero before the animation and returning to the UIView right after, but it feels very dirty. However, maybe I missed something. My code looks something like this:

 - (void)methodThatAnimates { [CATransaction begin]; { /* Must set to nil, otherwise the view just jumps to the new location. */ self.viewToAnimate.layer.delegate = nil; CAMediaTimingFunction *timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.4 :0 :0 :1.0]; [CATransaction setAnimationTimingFunction:timingFunction] self.viewToAnimate.layer.position = CGPoint(15.0, 0.0); /* Set delegate back to the view, as is required per the Apple documentation. */ self.viewToAnimate.layer.delegate = self.viewToAnimate; } [CATransaction commit]; } 

While this seems like a charm, but all the time I expect the appearance of some bizarre artifact due to a temporarily absent delegate.

+3
source

Maybe you should take a look at MTAnimation . This is the UIView category that provides jQuery functions such as synchronization functions.

+2
source

There are only a limited number of options with multimedia synchronization features. You can use the standard lists you list, or provide a pair of control points for a cubic bezier curve. However, the curve you generate cannot generate a value less than 0 or more than 1, because it is used to display linear time for the output time.

The checkpoint values ​​that you specify do not make sense as time values. If I am not mistaken, they will force time to go back and go to a value less than 0.

If you want arbitrary animation, such as size, you can use CAKeyFrameAnimation with a few breakpoints.

0
source

Source: https://habr.com/ru/post/1403851/


All Articles