代码之家  ›  专栏  ›  技术社区  ›  Pieter Jongsma

从CGaffinetTransform得到旋转

  •  6
  • Pieter Jongsma  · 技术社区  · 16 年前

    有没有可能从一个同样具有平移和缩放值的CGaffinetTransform得到旋转角度?如果是,怎么做?

    事先谢谢!

    5 回复  |  直到 11 年前
        1
  •  5
  •   zaph    16 年前

    struct CGAffineTransform {
       CGFloat a;
       CGFloat b;
       CGFloat c;
       CGFloat d;
       CGFloat tx;
       CGFloat ty;
    };
    
        2
  •  5
  •   Community Mohan Dere    9 年前
    atan2(rotationTransform.b, rotationTransform.d)
    

    atan2(rotationTransform.b, rotationTransform.a

    This duplicate was the basis for my original answer

        3
  •  0
  •   Dave DeLong    16 年前
        4
  •  0
  •   Felixyz    16 年前

    the source for XAffineTransform here read the API here

    final double scaleX = getScaleX0(tr);
    final double scaleY = getScaleY0(tr) * flip;
    return Math.atan2(tr.getShearY()/scaleY - tr.getShearX()/scaleX,
                      tr.getScaleY()/scaleY + tr.getScaleX()/scaleX);
    

        5
  •  0
  •   andrewchan2022    12 年前

    CGFloat radians = atan2f(self.view.transform.b, self.view.transform.a); 
    CGFloat degrees = radians * (180 / M_PI); 
    

    CGFloat angle = [(NSNumber *)[view valueForKeyPath:@"layer.transform.rotation.z"] floatValue];