iOS 角度获取及旋转

获取当前角度

CGFloat radius = atan2f(view.transform.b, view.transform.a);

CGFloat degree = radius * (360/ M_PI);

1、旋转到x度

view.transform = CGAffineTransformMakeRotation(x);

2、在现在旋转角度的基础上再旋转x度

CGAffineTransform currentTransform = view.transform;

CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, x); // 在现在的基础上旋转指定角度view.transform = newTransform;

恢复到0度

CGAffineTransform currentTransform = view.transform;

CGFloat rotation = (0.0 - recordDegree) * M_PI / 360.0f; // recordDegree记录现在的旋转角度

CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);

view.transform = newTransform;

你可能感兴趣的:(iOS 角度获取及旋转)