Objective c 如何围绕中心旋转CGContext?

Objective c 如何围绕中心旋转CGContext?,objective-c,sprite-kit,core-graphics,uigraphicscontext,Objective C,Sprite Kit,Core Graphics,Uigraphicscontext,我有以下代码来创建多色ImageContext: UIGraphicsBeginImageContext(self.view.frame.size); [self.imageToDelete drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound)

我有以下代码来创建多色ImageContext:

UIGraphicsBeginImageContext(self.view.frame.size);
[self.imageToDelete drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

CGColorRef mycolor;

mycolor = [[UIColor blueColor] CGColor];

CGPoint mid = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);

CGContextMoveToPoint(UIGraphicsGetCurrentContext(), mid.x, mid.y);


CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), mid.x, mid.y+50);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),3);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), mycolor);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());

mycolor = [[UIColor whiteColor] CGColor];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), mid.x, mid.y+50);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), mid.x, mid.y+75);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),3);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), mycolor);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());

mycolor = [[UIColor cyanColor] CGColor];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), mid.x, mid.y+75);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), mid.x, mid.y+100);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),3);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), mycolor);

CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());

self.imageToDelete = UIGraphicsGetImageFromCurrentImageContext();

[self.mainImage drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeCopy alpha:1.0];
[self.imageToDelete drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:1];
self.mainImage = UIGraphicsGetImageFromCurrentImageContext();

SKSpriteNode *node = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImage:self.mainImage]];
node.zPosition = 100;
node.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
node.size = self.mainImage.size;
[self addChild:node];

UIGraphicsEndImageContext();
结果是:


我想围绕屏幕中心(或这条线的顶部)旋转这条线,并保持原来的线。有没有办法复制并围绕中心点旋转?为了澄清,
mid
是一个CGPoint,定义为
(self.view.frame.size.width/2,self.view.frame.size.height/2)
,这是在精灵套件、iOS、Objective-C中完成的。

旋转围绕原点。若要围绕另一个点旋转,请将该点平移到原点,然后旋转并向后平移。

旋转围绕原点。若要围绕另一个点旋转,请将该点平移到原点,然后旋转并向后平移。

旋转围绕原点。若要围绕另一个点旋转,请将该点平移到原点,然后旋转并向后平移。

旋转围绕原点。若要围绕另一个点旋转,请将该点平移到原点,然后旋转并向后平移。

此处示例代码:此处示例代码:此处示例代码:此处示例代码:此处示例代码: