「IOSDrawingPractical UIKitSolutions」リーディングノート(1)-描画コンテキスト



Ios Drawing Practical Uikit Solutionsreading Notes Drawing Context



UIKitでは、座標の原点は左上隅から始まりますが、Quartzでは、座標の原点は左下隅から始まります。
画像

座標系は、コンテキストの作成方法によって異なります。 UIKit関数によって作成された場合は、UIKit座標系に準拠します。それ以外の場合は、Quartz座標系に準拠します。



Quartzコンテキストの座標系を垂直方向に反転して、QuartzのContext座標系をUIKitのContext座標系と同じにすることができます。コードは次のように表示されます。

- (void)FlipContextVertically:(CGSize) size{ CGContextRef context = UIGraphicsGetCurrentContext() if (context == NULL) { NSLog(@'Error:NO context to flip') return } CGAffineTransform transform = CGAffineTransformIdentity transform = CGAffineTransformScale(transform, 1.0f, -1.0f) transform = CGAffineTransformTranslate(transform, 1.0f, -size.height) CGContextConcatCTM(context, transform) }