简体   繁体   English

围绕其左上角旋转矩形

[英]Rotate Rectangle Around Its Upper Left Corner

Simply trying to rotate a rectangle around it's origin, or its upper left corner like so: 只需尝试围绕其原点或其左上角旋转一个矩形,如下所示:

在此处输入图片说明

Am using the following: 我正在使用以下内容:

panGestureRecognizer.view.transform = CGAffineTransformRotate(panGestureRecognizer.view.transform, (M_PI * angle) / 180);

But the rectangle is sort of rotating in a big loop. 但是矩形有点像是在大循环中旋转。 Is there some sort of translation I need to do to get this to work? 我需要进行某种翻译才能使其正常工作吗?

You just need to set the anchor point: https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instp/CALayer/anchorPoint 您只需要设置定位点: https : //developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instp/CALayer/anchorPoint

panGestureRecognizer.view.layer.anchorPoint = CGPointMake(0.0, 0.0);

Further Reading: For more advanced stuff you could try some of the tips detailed here for matrix transformations: https://stackoverflow.com/a/8536553/563381 进一步阅读:有关更高级的内容,您可以尝试此处详细介绍的一些有关矩阵转换的技巧: https : //stackoverflow.com/a/8536553/563381

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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