CGAffineTransformMakeRotation在外部点附近

有没有办法使用CGAffineTranformMAkeRotation围绕外部点旋转UIImage? 很多!

这是一个使用与CoreGraphics CGAffineTransform API格式相同格式的函数。

这工作正是其他“RotateAt()”API应该如何工作。

该操作表示以下规范的等价物:translate(pt.x,pt.y); 旋转(angular度); translate(-pt.x,-pt.y);

CGAffineTransform CGAffineTransformMakeRotationAt(CGFloat angle, CGPoint pt){ const CGFloat fx = pt.x, fy = pt.y, fcos = cos(angle), fsin = sin(angle); return CGAffineTransformMake(fcos, fsin, -fsin, fcos, fx - fx * fcos + fy * fsin, fy - fx * fsin - fy * fcos); } 

就像CGAffineTransformMakeRotation() ,angular度是弧度而不是度数。

将图像视图的图层的anchorPoint设置为(0,0)和(1,1)以外的内容,即view.layer.anchorPoint = CGPointMake(2,2)。

我已经解决了这个问题:我把我想旋转到另一个视图的UIImage。 视图是最大的图像视图,所以视图的中心点是uiimage视图的外部点,所以我旋转视图….

我刚刚给了这个镜头。 就像应该给你你正在寻找的结果…

 - (void)rotateView:(UIView *)view aroundPoint:(CGPoint)point withAngle:(double)angle{ //save original view center CGPoint originalCenter = view.center; //set center of view to center of rotation [view setCenter:point]; //apply a translation to bring the view back to its original point view.transform = CGAffineTransformMakeTranslation(originalCenter.x, originalCenter.y); //multiply the view's existing rotation matrix (the translation) by a rotation and apply it to the view //thereby making it rotate around the external point view.transform = CGAffineTransformConcat(view.transform, CGAffineTransformMakeRotation(angle)); } 

只是为了解释我的推理…

我们基本上正在做的是将视图转换到旋转的angular度,然后应用翻译使其看起来像原来的位置。 那么,如果我们通过视图的新的平移来旋转一个旋转,那么我们基本上旋转了整个视图和它的坐标系,所以看起来就像它在给定点上旋转一样。 我希望我解释得很好。 :| 如果没有,我build议在网上查找转换matrix,也许你可以find更好的解释他们如何堆积在那里!