UIimageView 围绕一个点旋转

UIimageView rotate around a point(UIimageView 围绕一个点旋转)

本文介绍了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 的中心旋转,你可以将你的任务分成 3 个部分,

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 围绕一个点旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:UIimageView 围绕一个点旋转