简体   繁体   中英

UIView resizing after rotation with CGAffineTransform

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

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!

First thing to note is that the view's frame property is out of bounds (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM