我有一个程序,其中CALayer必须旋转到某个值.
如何确定CALayer的当前旋转?
我有一个UIRotationGestureRecognizer来旋转图层:
如何确定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,1.0); } }
我从一层必须旋转一定数量的拼图开始.那么如何获得当前图层的旋转?
解决方法
你可以做数学,得到这样的角度:
CATransform3D transform = _baseLayer.transform; CGFloat angle = atan2(transform.m12,transform.m11);
但是更容易做到如下:
CGFloat angle = [(NSNumber *)[_baseLayer valueForKeyPath:@"transform.rotation.z"] floatValue];
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。