我使用 kCGBlendModeClear 混合模式来实现橡皮擦工具。它在 ios 中工作正常,但在 OS X 中不起作用。它在 OS X 中使用 kCGBlendModeClear 混合模式创建黑色线条。
这里是示例代码:
#if TARGET_OS_IPHONE
CGContextRef context = UIGraphicsGetCurrentContext();
#else
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
#endif
CGContextSaveGState(context);
CGContextSetLineWidth(context, 10);
CGContextSetRGBStrokeColor(context, 255.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(context, 100, 100);
CGContextAddLineToPoint(context, 200, 200);
CGContextStrokePath(context);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextMoveToPoint(context, 150, 150);
CGContextAddLineToPoint(context, 180, 180);
CGContextStrokePath(context);
CGContextRestoreGState(context);
iOS:
但在 OS X 中:
我也尝试更改 View 和 super View 的不透明属性和背景颜色,但没有帮助。
我知道透明颜色实际上是黑色,alpha 为 0,但我想知道为什么 OS X 中会忽略 alpha。
谢谢。
最佳答案
使用图层支持的 NSView,[view setWantsLayer:YES];
关于macos - 使用 kCGBlendModeClear 在 Mac OS X 上实现橡皮擦描边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14596404/