如何“旋转”一个图层/视图(例如就像你在enigmo中一样) [英] How to "rotate" a layer/view (e.g. just like you would in enigmo)

查看:167
本文介绍了如何“旋转”一个图层/视图(例如就像你在enigmo中一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何根据触摸移动图层。但我也希望能够旋转图像。



有没有示例代码演示如何做到这一点?


解决方案

最简单的方法是使用图层的transform属性:

  float angle = M_PI; // rotate 180°,or 1πradians 
layer.transform = CATransform3DMakeRotation(angle,0,0.0,1.0);

CATransform3DMakeRotation函数的第一个参数是旋转量,以弧度表示。接下来的三个描述要围绕其旋转的向量。这是描述z轴上的矢量,因此有效地垂直于屏幕。这将旋转图层,使其上下颠倒。


I know how to move a layer based on touch. But I would also like to be able to rotate the image.

Is there any sample code that shows how to do this? Or can anyone give me some advice?

Thanks!

解决方案

The simplest way to do this is using the layer's transform property:

float   angle = M_PI;  //rotate 180°, or 1 π radians
layer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0);

The first argument to the CATransform3DMakeRotation function is the amount to rotate, in radians. The next three describe the vector around which to rotate. This is describing a vector in the z-axis, so effectively perpendicular to the screen. This will rotate the layer so it's upside down.

这篇关于如何“旋转”一个图层/视图(例如就像你在enigmo中一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆