UIimageView rotate around a point(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,
- 进入旋转点
- 旋转
- 后退
并将它们链接起来.
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 围绕一个点旋转


- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01