How to set up a user Quartz2D coordinate system with scaling that avoids fuzzy drawing?

前端 未结 2 1281
独厮守ぢ
独厮守ぢ 2020-12-13 11:57

This topic has been scratched once or twice, but I am still puzzled. And Google was not friendly either.

Since Quartz allows for arbitrary coordinate systems using a

2条回答
  •  伪装坚强ぢ
    2020-12-13 12:15

    Well, as often, explaining the issue lead me to a solution.

    The problem is that the view transform property is applied to it after it has been drawn into a bit buffer. The scaling transform has to be applied before drawing, ie. in the drawRect method. So scratch the awakeFromNib I gave, and here is a correct drawRect:

    - (void)drawRect:(CGRect)rect {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGAffineTransform scale = CGAffineTransformMakeScale(6.0, 6.0);
        CGContextConcatCTM(context, scale);
        CGRect r = CGRectMake(10., 10., 10., 10.);
        CGFloat lineWidth = 0.1;
        CGContextStrokeRectWithWidth(context, r, lineWidth);
    }
    

提交回复
热议问题