诀窍可能在于这个 UIImage 方法
+ (UIImage *)imageWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation
其中方向是其中之一:)
typedef enum {
UIImageOrientationUp,
UIImageOrientationDown, // 180 deg rotation
UIImageOrientationLeft, // 90 deg CCW
UIImageOrientationRight, // 90 deg CW
UIImageOrientationUpMirrored, // as above but image mirrored along other axis. horizontal flip
UIImageOrientationDownMirrored, // horizontal flip
UIImageOrientationLeftMirrored, // vertical flip
UIImageOrientationRightMirrored, // vertical flip
} UIImageOrientation;
编辑:更新
我刚刚在覆盖 drawrect 的 UIView 子类中做了这个简单的代码示例,它工作得很好。它不使用 UIImage 方法,但工作方式相同。
UIImage *image = [UIImage imageNamed:@"image.png"];
CGContextRef _context = UIGraphicsGetCurrentContext();
CGContextSaveGState(_context);
CGContextDrawImage(_context, CGRectMake(100, 20, image.size.width, image.size.height), image.CGImage);
CGContextScaleCTM(_context, -1.0f, 1.0f);
CGContextDrawImage(_context, CGRectMake(-300, 20, image.size.width, image.size.height), image.CGImage);
CGContextRestoreGState(_context);