幅 200 x 高さ 100 の UIView サブクラス (TraceView) があり、ピクセルごとに描画しようとしています。この場合、横方向の 75% を横切る青い水平線を引こうとしています。代わりに、2 本の垂直の青い線 (端に 1 本、中央に 1 本) が表示され、75% まで上がります。私が使用している CGLayer は 90 度回転して 50% 縮小されているようです。これを修正するにはどうすればよいですか?
.m ファイルの先頭:
#define WORLD_WIDTH 200
#define WORLD_HEIGHT 100
#define ABGR_BYTES 4
@implementation TraceView
int theImage[WORLD_WIDTH][WORLD_HEIGHT];
drawRect のオーバーライド:
- (void)drawRect:(CGRect)rect {
CGContextRef theViewContext = UIGraphicsGetCurrentContext();
CGLayerRef theCGLayer = CGLayerCreateWithContext(theViewContext, rect.size, nil);
CGContextRef theCGLayerContext = CGLayerGetContext(theCGLayer);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext = CGBitmapContextCreate(theImage, WORLD_WIDTH, WORLD_HEIGHT, 8, WORLD_WIDTH * ABGR_BYTES, colorSpace, kCGImageAlphaPremultipliedLast);
// is ABGR
for(int i=0;i<150;i++) {
theImage[i][0]=0xFFFF0000;
}
CGImageRef image = CGBitmapContextCreateImage(bitmapContext);
CGContextDrawImage(theCGLayerContext, rect, image);
CGContextDrawLayerInRect(theViewContext, rect, theCGLayer);
}