关于ios绘图坐标系问题

来源:互联网 发布:淘宝签到在哪 编辑:程序博客网 时间:2024/06/15 21:53


在UIView 重载函数drawRect中 能取得当前的图形上下文(context) ,需要注意:

1. 此时上下文的坐标系 为 [1, 0, 0, -1, 0, bounds.height],知道这些才能有效的转换坐标系

2. CGContextSaveGState 保存当前状态,但坐标系并没重置,以后的操作都基于保存时的坐标系再转换变更

3. 坐标系操作都是累加,每一步变更都会影响到下一步的绘图

4. CGContextRestoreGState 会恢复坐标系到CGContextSaveGState时的状态(两者之间的坐标系变更失效)

5.绘图操作不影响坐标系


- (void)drawRect:(CGRect)rect {   CGContextRef context = UIGraphicsGetCurrentContext();    CGAffineTransform t = CGContextGetCTM(context);    NSLog(@"此时的坐标系为 ctm=%@",NSStringFromCGAffineTransform(t));   //扭转坐标系   t = CGAffineTransformInvert(t);   CGContextConcatCTM(t);/* //第二种常见的方法:CGContextScaleCTM(context, 1.0, -1.0);CGContextTranslateCTM(context, 0, -self.bounds.size.height);*/}


原创粉丝点击