如何在圆形路径中旋转图像

HOW TO ROTATE IMAGE in circular path

我想 rotate image(箭头)在 coreGraphics 中的圆形路径中,就像这张图片一样。在圆形路径中。

输入图像:

旋转后输出:

放三张图,旋转2&3图如下。

imageview2.transform = CGAffineTransformMakeRotation(M_PI/4);

imageview3.transform = CGAffineTransformMakeRotation(M_PI/2);

希望这对您有所帮助...

试试 UIcollectionview 它对我的情况很有效。

这将return旋转图像

- (UIImage *)rotateImage:(UIImage *)image onDegrees:(float)degrees
{
    CGFloat rads = M_PI * degrees / 180;
    float newSide = MAX([image size].width, [image size].height);
    CGSize size =  CGSizeMake(image.size.width, newSide);
    UIGraphicsBeginImageContext(size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(ctx, image.size.width, newSide/2);
    CGContextRotateCTM(ctx, rads);
    CGRect r = CGRectMake(0,-[image size].height/2,image.size.width,image. size.height);
    [image drawInRect:r];
    UIImage *i = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return i;
}

    UIImage *arrowRotated180  = [self rotateImage:[UIImage imageNamed:@"arrowImage"] onDegrees:180];

    UIImage *arrowRotated90  = [self rotateImage:[UIImage imageNamed:@"arrowImage"] onDegrees:90];