cgpath

Troubles using CGPathContainsPoint SWIFT

吃可爱长大的小学妹 提交于 2019-12-10 02:02:10
问题 I need to check if a CGPoint is inside a SKSpriteNode. After a little research, CGPathContainsPoint seems appropriated for my purpose. if CGPathContainsPoint(my_sprite_path, nil, my_point, false) { } But Xcode alerts me: Use of unresolved identifier CGPathContainsPoint I tried to import : import UIKit import CoreGraphics I'm using Xcode 8.0 beta 6. Did I miss anything? 回答1: As of Swift 3, many Core Graphics functions are now methods on the corresponding type. In your example: if my_sprite

Core Text: Render to an Odd Shape

主宰稳场 提交于 2019-12-09 00:57:26
问题 I am trying to render text to a shape that isn't a rectangle. The following code works when I add a rectangular path but not when I add an elliptical path. Ultimately, I'd like to draw to any path (L shape, etc), has anyone had any luck with this? -(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGMutablePathRef path = CGPathCreateMutable(); float w = 200.0; float h = 300.0; CGRect bounds =

Swift: How to add points to a closed CGPath?

ⅰ亾dé卋堺 提交于 2019-12-09 00:17:49
问题 I'd like to make SKSpriteNodes to move along letter outlines. I have many letters but here's one example: I would like the sprite to follow the red line. I found this answer that mostly covers my problem: Get path to trace out a character in an iOS UIFont The answer comes with this good and working example code: let font = UIFont(name: "HelveticaNeue", size: 64)! var unichars = [UniChar]("P".utf16) var glyphs = [CGGlyph](count: unichars.count, repeatedValue: 0) let gotGlyphs =

Encode and Decode CGMutablePathRef with ARC

淺唱寂寞╮ 提交于 2019-12-08 09:46:08
问题 Under ARC, is it possible to encode/decode a CGMutablePathRef (or its non-mutable form) using NSCoding ? Naively I try: path = CGPathCreateMutable(); ... [aCoder encodeObject:path] but I get a friendly error from the compiler: Automatic Reference Counting Issue: Implicit conversion of an Objective-C pointer to 'CGMutablePathRef' (aka 'struct CGPath *') is disallowed with ARC What can I do to encode this? 回答1: NSCoding is a protocol. Its methods can only be used with objects that conform to

Following a CGPath with SKAction without starting from beginning of CGPath

橙三吉。 提交于 2019-12-07 10:33:09
问题 I have an SKShape node that represents an ellipse. A player is placed on the current point of a Bezier Path that is based on the ellipse's CGPath: I have two actions that the player node can perform. The player can either follow the path clockwise or counterclockwise. rotateCounterClockwiseAction = SKAction.followPath(counterClockwisePath.CGPath, asOffset: false, orientToPath: true, duration: 1) rotateClockwiseAction = SKAction.followPath(clockwisePath.CGPath, asOffset: false, orientToPath:

Detecting collision, during a CAKeyFrameAnimation

折月煮酒 提交于 2019-12-06 09:37:31
Is it possible to detect the collision of two UIImageViews while one is travelling along a path during a CAKeyFrameAnimation? If so how is this done, I have tried multiple methods including checking both the CGRects for collision during the animation - but can't find a suitable method for performing a method during a CAKeyFrameAnimation and trying to detect collision of the path and the UIImageView. You need to get the properties from the presentation layer. It will have the best approximation of information that exists during animation. Access it by view.layer.presentationLayer Look at the

How to draw a filled path/shape in different colors

雨燕双飞 提交于 2019-12-06 09:03:59
问题 I need to color a shape on my screen any color I wish. I am currently trying to do this with a UIImage which I want to recolor to my desires. The only way to do this, as far as I know, is to take the individual pixels of the UIImage, which calls for many more lines of code that I would like to write to fix this problem. Is there any way to change the UIImage color other than what I have written? Would it be easier to draw the shape in context and fill it? TY. Update: The Hexagon is drawing

How to create a perfect half circle with CGPathAddCurveToPoint?

南笙酒味 提交于 2019-12-06 08:22:50
问题 I am trying to create a perfect right half circle of 15 points radius with CGPathAddCurveToPoint, like this: CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddCurveToPoint(path, NULL, 15, 0, 15, 30, 0, 30); It starts at the top middle of the circle. Then the first control point is set to the top right corner of the circle's bounding box. The second control point is set to the bottom right corner of the circle's bounding box. The circle ends at bottom middle of the bounding box. But when drawn,

How to get the path Quartz is using to stroke a NSBezierPath

百般思念 提交于 2019-12-06 08:12:43
问题 I'm using this code to stroke a NSBezierPath with a wide, dashed, black line. ( c and strForBezier are defined somewhere else) NSGlyph glyph; for(n = 0; n < len; n++) { glyph = [font glyphWithName: [strForBezier substringWithRange:NSMakeRange(n, 1)]]; [path appendBezierPathWithGlyph: glyph inFont: font]; } CGFloat pattern2[4]; pattern2[0]=5*c; pattern2[1]=2*c; pattern2[2]=2*c; pattern2[3]=2*c; [path setLineDash:pattern2 count:4 phase:0]; [path setLineWidth:c]; [path stroke]; [[NSColor

CGPath adding a curve between points

只谈情不闲聊 提交于 2019-12-06 04:34:27
问题 So I have a function which randomly generates some CGPoints I then create a CGPath from these points. I use this path in a keyframe animation to animate a view around the screen. The path is generated using the code below: - (CGMutablePathRef)generatePathFromCoordinates:(NSArray *)coordinates { CGMutablePathRef path = CGPathCreateMutable(); CGPoint point = [(NSValue *)[coordinates objectAtIndex:0] CGPointValue]; CGPathMoveToPoint(path, nil, point.x, point.y); for (int i=1; i < coordinates