gpt4 book ai didi

ios - 确定 CALayer 旋转了多少

转载 作者:技术小花猫 更新时间:2023-10-29 10:45:12 26 4
gpt4 key购买 nike

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

- (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);
}
}

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

最佳答案

你可以这样计算并得到角度:

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

但这样做更容易:

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

来自documentation :

Core Animation extends the key-value coding protocol to allow getting and setting of the common values of a layer's CATransform3D matrix through key paths. Table 4 describes the key paths for which a layer’s transform and sublayerTransform properties are key-value coding and observing compliant

关于ios - 确定 CALayer 旋转了多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9712136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com