UIimageView绕点旋转 [英] UIimageView rotate around a point

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

问题描述

我有一个图像(一条直线),并试图从特定点以一定角度旋转它.发生的是图像从其中心点旋转.我不希望通过这种方式可以使图像的基础保持不变,并且可以按照我想要的角度旋转,就像时钟一样. 我用

I've got an image (a straight line) and am trying to rotate it in some angle from a specific point. What happens is that the image is rotated from the center point of itself. I wan't a way through which the base of the image remains the same and it rotates in the angle I want to, just as in case of a clock. I use

Compass2.layer.anchorPoint= CGPointMake(0.5,1);
[Compass2 setTransform:CGAffineTransformMakeRotation(XXXX)];

但是它显示了访问属性的未知"achorPoint"组件. 谁能给我一些解决方法

However it shows Accessing unknown 'achorPoint' component of a property. Can anyone give me some solutions

推荐答案

CGAffineTransform只是描述旋转,平移和缩放的矩阵.

Well a CGAffineTransform is just a Matrix describing rotation, translation and scaling.

记住您可以使用

CGAffineTransform CGAffineTransformConcat ( CGAffineTransform t1, CGAffineTransform t2 );

链接转换.这基本上意味着您要乘以转换矩阵.

to chain up transforms. This basically just means you are multiplying the transformation matrizes.

因此,您知道,标准Rotation只是绕着UIImageView的中心旋转,因此您可以将任务分为三部分,

So since you know, the standard Rotation just rotates around the center of the UIImageView, you could break up your task into 3 parts,

  1. 移动到旋转点
  2. 旋转
  3. 后退

并将它们链接起来.

CGAffineTransform t = imageView.transform;
CGPoint p = rotationPoint - imageView.center;
imageView.transform = CGAffineTransformTranslate(
CGAffineTransformRotate( CGAffineTransformTranslate(t, p.x, p.y), angle) , -p.x, -p.y);

我没有测试此代码,但是您应该通过这种方式获得解决方案.

I didn't test this code, but you should get a solution along this way.

我还意识到我没有使用串联.如果使用"CGAffineTransformMake ...",则需要使用串联.我只是将各个函数放在一起.

I also realized I didn't use the Concatenation. You need to use the concatenation if you use "CGAffineTransformMake...". I just put the functions into each other.

这篇关于UIimageView绕点旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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