使用CGAffineTransform旋转后调整UIView的大小 [英] UIView resizing after rotation with CGAffineTransform

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

问题描述

这是我的第一个问题,向大家问好:)

it's my first question here, so hello to everyone :)

我需要获得类似于页面/主题图像处理的结果.我有可以旋转/缩放等的uiview.我在每个角落都有用于调整视图大小的手柄.一切正常(缩放/旋转),但是当图像旋转时,我尝试通过移动手柄来更改其大小时,一切都会出错,或者图像更改其大小无法预测,或者在屏幕上四处移动.

I need to achieve results similar to pages/keynote image manipulation. I have uiview which I can rotate/scale and so on. I have handles on each corner for resizing view. Everything working (scaling/rotating) but when image is rotated and I try to change its size by moving handles everything goes wrong, or image change its size unpredictable or it's moving all around screen.

如果能找到一些类似的例子或可以做的事,我会感激任何方向或建议.

I'll appreciate any direction or suggestion where I can find some similar examples or what I can do.

这是我想要获得的视频. 示例

here is a video what I like to get. example

推荐答案

我自己已经解决了这个问题.我非常有信心地说,没有简单的方法可以做到这一点,您只需要拿起一支笔和一支笔就可以了.论文,然后潜入一些相当繁琐的三角学中!

I've worked on this problem myself. I'm fairly confident in saying that there is no easy way to do this, you just need to pick up a pen & paper and dive into some fairly tedious trigonometry!

首先要注意的是,视图的frame属性超出范围(即,对其应用旋转变换时,其值是不确定的),因此,您必须改为使用boundscenter属性.然后,您只需要根据当前角度计算新的边界和中心位置.烦人的是,知道bounds与水平& amp;不对齐.垂直轴,而center坐标当然是,因此需要一个笔&.纸.对于每个手柄,您的计算将略有不同,但是您可以通过复制一个手柄的代码并更改一些加/减符号来逃脱这种麻烦.

First thing to note is that the view's frame property is out of bounds (i.e. its value is undefined when a rotation transform is applied to it), so you must instead use the bounds and center properties. Then you just need to compute the new bounds and center position based on the current angle. The tedium comes in knowing that the bounds are not aligned to the horizontal & vertical axis anymore, whereas the center coords of course are, hence the need for a pen & paper. Your calculations will be very slightly different for each handle, however you can pretty much just get away with copying one handle's code and changing some plus/minus signs.

实际上,老实说,一旦您勇于做出决定,那就还不错.我自己的实现限制了要调整大小的视图的大小和宽度,这是最难的一点.使事情按用户期望的方式工作可能会花费一些工作,但这是值得的.

Actually to be honest, once you've braved the decision to do it, it's not too bad. My own implementation limited the size and width of the view being resized, and this was the hardest bit. Getting things to behave as the user would expect may take a bit of work, but it's worth it.

这篇关于使用CGAffineTransform旋转后调整UIView的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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