- 翻轉坐標系因為UIKit的坐標系和CGContext所在的坐標系不同 UIKit下面圓點在左上角 而CGContext所在的坐標系在左下角
未解決的時候
CGContextDrawImage(context, CGRectMake(50, 0, 100, 30), [UIImage imageNamed:@"douyu1"].CGImage);
drawImage.png
方法1:
顛倒坐標系
這樣如果你想坐標是 100 10 你該改成坐標 100 (rect.size.height-imageHeight-10)
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(50, rect.size.height - 30, 100, 30), [UIImage imageNamed:@"douyu1"].CGImage);
方法二:
使用方法
不需要關心坐標系相關的轉換系統幫你做了
- (void)drawInRect:(CGRect)rect