旋转 UIImage 并移动 [英] Rotate UIImage and Move

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

问题描述

我已经搜索了太多次堆栈溢出,也发布了一个问题,但徒劳无功.我需要在我的拼贴应用程序中实现一个功能,用户可以在其中旋转 uiimage 并将其作为旋转图像移动.知道怎么做吗?如果需要,我会尝试所有这些.最近两天一直在寻找它.

I have searched stack overflow too many times and also posted a question but in vain. I need to implement a function in my collage app where user can rotate a uiimage and move it as rotated image. Any idea of how to do it? I will try all of them if needed. Am being frustrated searching for it for last two days.

起初我使用 CGAffineTransformMakeRotation(angle) 旋转了 UIImage 的框架.它正在工作,但是在旋转后移动图像时,它会产生失真.那么还有其他方法吗?

At first i have rotated the frame of the UIImage using CGAffineTransformMakeRotation(angle). It was working but when moving the image after rotation, it was creating distortion. So any other way of doing it?

要说清楚,旋转角度自定义.

edit: to make it clear, rotation angle is custom.

推荐答案

检查了一些类似的问题 (旋转变换后更改 uiview 大小如何在 CGAffineTransformIdentity 时调整 UIView 的大小并阅读 关于 CGAffineTransform 的官方文档 我得出了一些简单的结论.将在下面解释它们.

Having examined some of the similar questions (Change uiview size after rotation transform and How to resize the UIView when CGAffineTransformIdentity) and read the Official documentation about CGAffineTransform I have come to some simple conclusions. Will explain them below.

当您使用 CGAffineTransform 对某些具有跟随帧变换的对象时,您必须使用一些规则才能获得正确的结果:

When you use CGAffineTransform for some object with followed frame transform you must use some rules for obtain correct result:

  1. 如果对象的变换属性等于CGAffineTransformIdentity,您可以无限制地更改对象的框架或使用CGAffineTransform.

  1. If transform property of object is equal CGAffineTransformIdentity you can change frame of object or use CGAffineTransform without restriction.

如果对象的变换属性不等于 CGAffineTransformIdentity 并且您想在没有 CGAffineTransform 的情况下更改对象的框架:
a) 将对象转换的值保存到某个本地(或其他类型)变量
b) 将对象的变换属性设置为 CGAffineTransformIdentity
c) 改变对象的框架
d) 从本地(或其他类型)变量中恢复转换值.

If If transform property of object is not equal CGAffineTransformIdentity and you want change frame of object without CGAffineTransform:
a) save value of object transform to some local (or another type) variable
b) set transform property of object to CGAffineTransformIdentity
c) change frame of object
d) restore transform value from local (or another type) variable.

遵守这些简单的规则将有助于避免许多问题.

Compliance with these simple rules will help avoid many problems.

注意:你必须记住,当你使用 CGAffineTransformConcat 时,所有的变换都是累加的.例如:如果要将对象从 6 度旋转到 7 度,则必须添加变换旋转到 1 度,而不是 7.否则将获得旋转 6 + 7 = 13 度.

Note: you must remember, when you use CGAffineTransformConcat all transform totalized. For example: if you want rotate object from 6 degree to 7 degree, you must add transform rotate to 1 degree, not to 7. Otherwise you obtain rotation 6 + 7 = 13 degree.

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

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