我正在尝试将 iOS 代码转换为 OSX 代码,并且在图形移植方面遇到了一些困难。
在iOS下我有这个:
NSRect rect = NSMakeRect(centerX.doubleValue - width.doubleValue / 2,
centerY.doubleValue - height.doubleValue / 2,
width.doubleValue, height.doubleValue);
UIBezierPath * path = nil;
switch (self.shape)
{
case HSTargetShapeInvisible:
path = [UIBezierPath bezierPath];
break;
case HSTargetShapeOval:
path = [UIBezierPath bezierPathWithOvalInRect:rect];
break;
case HSTargetShapeRectangle:
path = [UIBezierPath bezierPathWithRect:rect];
break;
default:
break;
}
CGAffineTransform translate = CGAffineTransformMakeTranslation(-1 * centerX.doubleValue,
-1 * centerY.doubleValue);
[path applyTransform:translate];
CGAffineTransform rotate = CGAffineTransformMakeRotation(rotation.doubleValue / 180 * M_PI);
[path applyTransform:rotate];
translate = CGAffineTransformMakeTranslation(centerX.doubleValue, centerY.doubleValue);
[path applyTransform:translate];
这完美地工作......然后我为OSX重写了这种方式:
NSRect rect = NSMakeRect(centerX.doubleValue - width.doubleValue / 2,
centerY.doubleValue - height.doubleValue / 2,
width.doubleValue, height.doubleValue);
NSBezierPath * path = nil;
switch (self.shape)
{
case HSTargetShapeInvisible:
path = [NSBezierPath bezierPath];
break;
case HSTargetShapeOval:
path = [NSBezierPath bezierPathWithOvalInRect:rect];
break;
case HSTargetShapeRectangle:
path = [NSBezierPath bezierPathWithRect:rect];
break;
default:
break;
}
NSAffineTransform *rot = [NSAffineTransform transform];
NSAffineTransform *pos = [NSAffineTransform transform];
[pos translateXBy:-1*centerX.doubleValue yBy:-1*centerY.doubleValue];
[rot rotateByRadians:rotation.doubleValue / 180 * M_PI];
[pos translateXBy:centerX.doubleValue
yBy:centerY.doubleValue ];
[rot appendTransform:pos];
[path transformUsingAffineTransform:rot];
而这并不相同。有谁知道问题出在哪里?!
任何形式的帮助都非常感谢!