本文介绍了确定CALayer旋转了多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,其中CALayer必须旋转到某个值。
如何确定CALayer的当前轮换?
我有一个旋转图层的UIRotationGestureRecognizer:

I have a program in which a CALayer has to be rotated to certain value.How can I determine the current rotation of a CALayer?I have a UIRotationGestureRecognizer that rotates the layer:

- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer == rotationGestureRecognizer) {
        NSLog(@"gestureRecRotation: %f", rotationGestureRecognizer.rotation);
        CATransform3D current = _baseLayer.transform;
        _baseLayer.transform = CATransform3DRotate(current, rotationGestureRecognizer.rotation * M_PI / 180, 0, 0, 1.0);
    }
}

我从一个必须旋转的图层开始一定数量适合拼图。那么如何获得图层的当前旋转?

I start with a layer that has to be rotated a certain amount to fit a puzzle. So how do I get the current rotation of the layer?

推荐答案

您可以进行数学计算并获得如下角度:

You can do the math and get the angle like this:

CATransform3D transform = _baseLayer.transform;
CGFloat angle = atan2(transform.m12, transform.m11);

但更容易做到如下:

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






来自:

这篇关于确定CALayer旋转了多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:25