CATransaction rotate layer 360 degree strange

前端 未结 1 1477
萌比男神i
萌比男神i 2020-12-22 06:54

I want to perform an infinite 360 degrees rotation animation, so I coded:

- (void)rotate
{
    __weak typeof(self) weakSelf = self;

    [CATransaction begin         


        
1条回答
  •  庸人自扰
    2020-12-22 07:16

    It's an edge case. With implicit animation, you are not able to say "rotate clockwise this amount". You are merely saying "set the transform to this value, and animate that effect." Well, how should that change be animated? The runtime has to make up an answer, and it isn't obvious how to do that. A transform of rotation by M_PI is the same "distance" in both directions, so the answer it makes up is arbitrary. You can see the problem even more clearly if you supply a value of M_PI+0.1 vs. a value of M_PI-0.1; you actually get reverse results: one keeps turning clockwise, the other keeps turning counterclockwise.

    With CABasicAnimation, on the other hand, you have a from-value (implicit or explicit) and a to-value, so you are able to express the notion "increase" (i.e. a positive difference means turn clockwise). It's even clearer if you animate by setting just the byValue.

    0 讨论(0)
提交回复
热议问题