好吧,我还没找到它。如果我想用每像素核心图形进行绘制,该怎么办?就像......我想画一条线到像素(45,61)和(46,63),而不是画到点(23,31)或类似的东西。那么这种情况我该怎么办呢?
我应该使用类似的东西:
CGContextAddLineToPoint(context,22.5,30.5);
CGContextAddLineToPoint(context,23,31.5);
或者有更好的方法吗?
我知道 contentScaleFactor
但我应该将其用作(例如在绘制某些函数时):
for(int x=bounds.origin.x; x<=bounds.origin.x+bounds.size.width*[self contentScaleFactor]; i++)
CGContextAddLineToPoint(context,x/[self contentScaleFactor],y(x/[self contentScaleFactor]));
我知道示例代码并不出色,但我想您会明白的。
我将非常感谢您的帮助,因为我对所有这些比例因子的东西有点困惑。
最佳答案
听起来您正在做 iOS uTunes 斯坦福类(class)的作业 3? :)
我认为您走在正确的道路上,因为我的实现看起来非常相似:
for(int x=self.bounds.origin.x; x<=self.bounds.origin.x + (self.bounds.size.width * self.contentScaleFactor); x++) {
//获取缩放后的 X 值来询问 dataSource
CGFloat axeX = (x/self.contentScaleFactor - self.origin.x)/self.scale;
//这里使用axeX进行测试,绘制x=y图
//将 axeX 替换为 dataSource Y 点计算
CGFloat axeY = -1 * ((axeX * self.scale) + self.origin.y);
if (x == self.bounds.origin.x) {
CGContextMoveToPoint(context, x/self.contentScaleFactor, axeY);
} 别的 {
CGContextAddLineToPoint(context, x/self.contentScaleFactor, axeY);
}
}
在 iOS-Sim iPhone4 (contentScaleFactor 1.0) + iPhone4S 设备 (contentScaleFactor 2.0) 上测试。
我很高兴其他读者可能做出的改进,因为我仍在学习。
关于objective-c - 核心图形拖动像素而不是点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9345559/