- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否有人可以帮忙。基本上我在下面有一些 Objective C 代码,有谁知道我如何将它附加到 Mac OS X 而不是 iOS 的 CAShapeLayer 上?
****//// Color Declarations
NSColor* fillColor = [NSColor colorWithCalibratedRed: 0 green: 0.886 blue: 0.886 alpha: 1];
NSColor* strokeColor = [NSColor colorWithCalibratedRed: 0 green: 0 blue: 0 alpha: 1];
//// Star Drawing
NSBezierPath* starPath = [NSBezierPath bezierPath];
[starPath moveToPoint: NSMakePoint(106, 91.5)];
[starPath lineToPoint: NSMakePoint(110.21, 82.56)];
[starPath lineToPoint: NSMakePoint(119.18, 86.7)];
[starPath lineToPoint: NSMakePoint(116.65, 77.15)];
[starPath lineToPoint: NSMakePoint(126.19, 74.56)];
[starPath lineToPoint: NSMakePoint(118.11, 68.86)];
[starPath lineToPoint: NSMakePoint(123.75, 60.75)];
[starPath lineToPoint: NSMakePoint(113.91, 61.58)];
[starPath lineToPoint: NSMakePoint(113.01, 51.74)];
[starPath lineToPoint: NSMakePoint(106, 58.7)];
[starPath lineToPoint: NSMakePoint(98.99, 51.74)];
[starPath lineToPoint: NSMakePoint(98.09, 61.58)];
[starPath lineToPoint: NSMakePoint(88.25, 60.75)];
[starPath lineToPoint: NSMakePoint(93.89, 68.86)];
[starPath lineToPoint: NSMakePoint(85.81, 74.56)];
[starPath lineToPoint: NSMakePoint(95.35, 77.15)];
[starPath lineToPoint: NSMakePoint(92.82, 86.7)];
[starPath lineToPoint: NSMakePoint(101.79, 82.56)];
[starPath closePath];
[fillColor setFill];
[starPath fill];
[strokeColor setStroke];
[starPath setLineWidth: 1];
[starPath stroke];****
最佳答案
CAShapeLayer
的路径属性是 CGPathRef
,但是,与 iOS 的 [UIBezierPath CGPath]
不同,令人惊讶的是没有任何内置方法来转换 OSX NSBezierPath
到 CGPathRef
.但是,在 Apple 文档中,他们在 https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/CocoaDrawingGuide/Paths/Paths.html#//apple_ref/doc/uid/TP40003290-CH206-SW2 发布了一个片段来进行转换。 :
@implementation NSBezierPath (BezierPathQuartzUtilities)
// This method works only in OS X v10.2 and later.
- (CGPathRef)quartzPath
{
int i, numElements;
// Need to begin a path here.
CGPathRef immutablePath = NULL;
// Then draw the path elements.
numElements = [self elementCount];
if (numElements > 0)
{
CGMutablePathRef path = CGPathCreateMutable();
NSPoint points[3];
BOOL didClosePath = YES;
for (i = 0; i < numElements; i++)
{
switch ([self elementAtIndex:i associatedPoints:points])
{
case NSMoveToBezierPathElement:
CGPathMoveToPoint(path, NULL, points[0].x, points[0].y);
break;
case NSLineToBezierPathElement:
CGPathAddLineToPoint(path, NULL, points[0].x, points[0].y);
didClosePath = NO;
break;
case NSCurveToBezierPathElement:
CGPathAddCurveToPoint(path, NULL, points[0].x, points[0].y,
points[1].x, points[1].y,
points[2].x, points[2].y);
didClosePath = NO;
break;
case NSClosePathBezierPathElement:
CGPathCloseSubpath(path);
didClosePath = YES;
break;
}
}
// Be sure the path is closed or Quartz may not do valid hit detection.
if (!didClosePath)
CGPathCloseSubpath(path);
immutablePath = CGPathCreateCopy(path);
CGPathRelease(path);
}
return immutablePath;
}
@end
layer.path = [starPath quartzPath];
关于xcode4.5 - 如何将 NSBezierPath 附加到 CAShapeLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17788870/
我通过创建圆形 NSBezierPath 并将其添加到图形上下文的剪切区域,在自定义 View 的中心绘制圆形图像。这工作得很好,但我想知道是否可以提高绘制 View 背景(圆角居中图像外部的区域)的
我正在 NSImageView 上绘制一条 NSBezierPath 线。我正在创建 NSBezierPath 对象,设置 moveToPoint,设置 lineToPoint,设置 setLineW
是否可以为 NSBezierPath 创建自定义破折号样式? 即我想要一条线,比如说,箭头全部指向笔划的方向。 例如,这样的事情...... ->--->--->--->---> 任何想法表示赞赏..
我有以下绘图代码: [[NSColor redColor] set]; NSRect fillRect = NSMakeRect(bounds.size.width - 20.0f, 0.0f, 20
我创建了一个 NSBezierPath ,并在其上调用了 -lines 。如何在不取消分配对象的情况下从 View 中删除/删除它? 最佳答案 -lines 消息告诉 NSBezierPath 在当前
我想在 DrawRect 中使用 NSBezierPath 在我的自定义 NSView 周围绘制一个 1px 宽的边框: BorderColor.Set(); var path = NSBezierP
我有一个 NSBezierPath 需要半透明填充。当我用纯色填充它时,我得到了预期的结果。然而,当填充半透明颜色时,我得到一 strip 有圆形笔划但奇怪的矩形填充的路径。它看起来像: 我没有填充整
在使用我的应用程序时,我遇到了一些绘图问题: 我想知道为什么,回到 Obj-c,-moveToPoint() 和 -lineToPoint() 可以毫无问题地绘制所有内容,而现在,通过 swift,可
我画了一个红色圆圈。然后我想删除它。我该怎么做? class Red: NSView { var red = 255 var green = 0 var blue = 0
我第一次在 macOS 应用程序中使用 NSBezierPath、CAShapeLayer 和 CABasicAnimation。我关注了this tutorial作为起点(它与 UIBezierPa
NSBezierPath 提供了一个名为 bounds 的 API,它返回没有控制点的边界。UIBezierPath 中是否有任何等效的 API 来返回不包括控制点的路径边界? 最佳答案 我得到了解决
我遇到以下问题。我正在编写自己的类,它必须绘制指定大小的圆,并用渐变填充它。 我用一个圆圈作为 NSBezierPath 来制作它,我使用它绘制渐变 [gradient drawInBezierPat
我正在尝试画一个简单的图表。我有由线连接的正方形。这些线条是用 NSBezierPath 绘制的。我对线条使用随机颜色,这样我就可以跟随它们。我的问题是线条颜色改变。 输出 - 代码 - 我删除了绘制
我想知道是否可以在绘制的 NSBezierPath 上设置工具提示。 我问这个问题的原因如下:我正在将 NSRect 形式的形状添加到 View 中。这些矩形代表了历史时期。看到该期间的开始年份和结束
我目前正在将我的 jruby/java2d 图形绘制/布局应用程序移植到 macruby/cocoa。因此我需要获取开放的 NSBezierPath 与封闭的 NSBezierPath 的交点。 在
我尝试使用 NSBezierPath 在 300x300 像素矩形中绘制幂函数曲线,如下所示: -(void)drawPowerCurve:(float)power points:(int)numbP
好的,所以我尝试绘制一个虚线框,该虚线框被分割为我要放置内容的部分。这是我的代码: NSBezierPath *path = [NSBezierPath bezierPathWithRect:dirt
我正在制作一个简单的绘图应用程序,并使用 NSBezierPath 来绘制线条。我正在对 NSView 进行子类化。我需要制定一种方法,允许用户更改下一条路径的颜色和大小(因此用户按下一个按钮,然后下
我想更改我绘制的按钮的填充(我将 NSButton 子类化) 这是我已经得到的代码: - (void)drawRect:(NSRect)dirtyRect { // Drawing code here
使用 NSBezierPath 绘制不同的线条(用于图表)时,我在更改线条颜色/宽度时遇到了一些非常基本的问题。下面的代码应该清楚地表明我想要做什么: #import "DrawTest.h" @im
我是一名优秀的程序员,十分优秀!