- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我能够使用任何选定的字体和大小生成字符的 UIBezierPath
。现在我想在贝塞尔曲线路径之间制作一条 eclipse 刻线。我可以得到贝塞尔路径的中心点吗?或者我可以制作中心虚线并沿着那条路径走的任何其他方式?
下面是我的代码
Reference Link. I want something like this. :
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 568, 568) cornerRadius:0];
UIBezierPath *circlePath = [self createArcPath];
[path appendPath:circlePath];
[path setUsesEvenOddFillRule:YES];
shapeView = [CAShapeLayer layer];
shapeView.geometryFlipped = false;
shapeView.path = path.CGPath;
shapeView.fillRule = kCAFillRuleEvenOdd;
shapeView.fillColor = [UIColor grayColor].CGColor;
shapeView.opacity = 1.0;
shapeView.lineDashPattern = @[@2, @3];
[self.view.layer addSublayer:shapeView];
CGFloat dashes[] = {2, 3};
[path setLineDash:dashes count:2 phase:0];
- (UIBezierPath *)createArcPath
{
// Create path from text
// See: http://www.codeproject.com/KB/iPhone/Glyph.aspx
// License: The Code Project Open License (CPOL) 1.02 http://www.codeproject.com/info/cpol10.aspx
letters = CGPathCreateMutable();
CTFontRef font = CTFontCreateWithName(CFSTR("Helvetica-Bold"),80, NULL);
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)font, kCTFontAttributeName,//د
nil];//ج
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"H"
attributes:attrs];
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString);
CFArrayRef runArray = CTLineGetGlyphRuns(line);
// for each RUN
for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++)
{
// Get FONT for this run
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex);
CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName);
// for each GLYPH in run
for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++)
{
// get Glyph & Glyph-data
CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1);
CGGlyph glyph;
CGPoint position;
CTRunGetGlyphs(run, thisGlyphRange, &glyph);
CTRunGetPositions(run, thisGlyphRange, &position);
// Get PATH of outline
{
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL);
CGAffineTransform t = CGAffineTransformMakeTranslation(position.x+200, position.y+80);
CGPathAddPath(letters, &t, letter);
CGPathRelease(letter);
}
}
}
CFRelease(line);
self.path = [UIBezierPath bezierPath];
[self.path appendPath:[UIBezierPath bezierPathWithCGPath:letters]];
return self.path;
}
最佳答案
Can I get the center points of the bezier path along? Or any other way that I can make the center dotted line and follow that path?
要知道用户的手指是否沿着路径移动,您必须路径上的命中检测。
To determine whether a touch event occurred on the filled portion of a path, you can use the containsPoint: method of UIBezierPath. This method tests the specified point against all closed subpaths in the path object and returns YES if it lies on or inside any of those subpaths.
If you want to do hit-testing on the stroked portion of the path (instead of the fill area), you must use Core Graphics. The CGContextPathContainsPoint function lets you test points on either the fill or stroke portion of the path currently assigned to the graphics context.
下面的方法测试指定的点是否与指定的路径相交。 inFill 参数让调用者指定是否应针对路径的填充部分或描边部分测试该点。调用者传入的路径必须包含一个或多个闭合的子路径,命中检测才能成功。
针对路径对象的测试点。
- (BOOL)containsPoint:(CGPoint)point onPath:(UIBezierPath *)path inFillArea:(BOOL)inFill
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGPathRef cgPath = path.CGPath;
BOOL isHit = NO;
// Determine the drawing mode to use. Default to
// detecting hits on the stroked portion of the path.
CGPathDrawingMode mode = kCGPathStroke;
if (inFill)
{
// Look for hits in the fill area of the path instead.
if (path.usesEvenOddFillRule)
mode = kCGPathEOFill;
else
mode = kCGPathFill;
}
// Save the graphics state so that the path can be removed later.
CGContextSaveGState(context);
CGContextAddPath(context, cgPath);
// Do the hit detection.
isHit = CGContextPathContainsPoint(context, point, mode);
CGContextRestoreGState(context);
return isHit;
}
查看此链接以了解更多关于 Hit-Detection on a Path 的信息
获取路径中心
您可以获得路径的宽度作为 myPath.bounds.size.width;
并获得路径的中心只需将宽度除以 2。
并绘制虚线检查此 answer
在任何 UIBezierPath
上制作虚线为:
CGFloat dashes[] = {2, 3};
//passing an array with the values {2,3} sets a dash pattern that alternates between a 2 space-unit-long painted segment and a 3 space-unit-long unpainted segment.
UIBezierPath *path = [UIBezierPath bezierPath];
[path setLineDash:dashes count:2 phase:0];
并在 CAShapeLayer
上划线使用属性 lineDashPattern
作为:
shapeView.lineDashPattern = @[@2, @3];
关于ios - 获取 UIBezierpath 的中心点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39012886/
如何让div的中心点作为旋转的中心点。 我遇到了 this虽然我正在做一些研究,但我似乎无法将其融入我的研究。 这就是帖子所建议的。但不起作用。$(area).css('-webkit-transfo
您好,我正在做一个应用程序,在我的应用程序中有一个 map 页面,所以我实现了 Google Maps V2,我遇到了一个问题,当我滚动 map 时,我想获得 map 的中心点,如果我滚动 map ,
我正在玩一个简单的 2d 游戏,我正在尝试从级别 1(场景一)切换到级别 2(场景二)。为了测试,两个级别包含相同的内容。这是我的转换代码: let transition = SKTransi
我有一个覆盖大部分屏幕区域的 map 的 View 。 在 map 的顶部,我有一些图像、按钮、文本框。它们位于 map 的顶部,我在这里称其为“无用 map ”,而底部则用于实际查看 map 。这是
给定一个纯白色背景上的对象,有人知道 OpenCV 是否提供了从捕获的帧中轻松检测对象的功能吗? 我正在尝试定位对象(矩形)的角点/中心点。我目前这样做的方式是通过蛮力(扫描对象的图像)并且不准确。我
我试图确保我的 map 中心点位于 kml 层的边界内,我无法找到很多相关信息,但我修改了来自 here 的一些代码。这似乎可行,但当然行不通。 从 Google Maps API 中,我无法判断 .
我试图在用户滚动 UIScrollView 时创建一个非常简单的视差效果。我在我的 ScrollView 上使用 scrollViewDidScroll 方法,一切正常。我可以记录该方法的所有内容,因
我正在使用 svg.js 和出色的 svg-pan-zoom 插件 ( https://github.com/ariutta/svg-pan-zoom )。 现在我想要一个按钮,当我单击它时,它会在我
我是一名优秀的程序员,十分优秀!