cashapelayer

Custom image mask in iOS

╄→尐↘猪︶ㄣ 提交于 2019-11-28 05:09:11
I have a issue with masking images. I do game "puzzle" and have to make custom images. I found and tried 2 way of custom cropping: Using CALayer.mask property. Using UIImage.mask property. In first option i create my custom path, then assign it to CAShapeLayer.path property, then assign CAShapeLayer to CALayer.mask property. At the end i have custom cropped image. In second option i use firstly use CGImageMaskCreate() method (i use previously created black mask images of puzzle), then CGContextClipToMask() . In either options i have problem with performance (mostly when i crop image into 16

How to add a border to a circular image with mask

最后都变了- 提交于 2019-11-28 05:05:31
问题 This is my attempt: func round() { let width = bounds.width < bounds.height ? bounds.width : bounds.height let mask = CAShapeLayer() mask.path = UIBezierPath(ovalInRect: CGRectMake(bounds.midX - width / 2, bounds.midY - width / 2, width, width)).CGPath self.layer.mask = mask // add border let frameLayer = CAShapeLayer() frameLayer.path = mask.path frameLayer.lineWidth = 4.0 frameLayer.strokeColor = UIColor.whiteColor().CGColor frameLayer.fillColor = nil self.layer.addSublayer(frameLayer) } It

How to draw a smooth circle with CAShapeLayer and UIBezierPath?

前提是你 提交于 2019-11-28 02:41:17
I am attempting to draw a stroked circle by using a CAShapeLayer and setting a circular path on it. However, this method is consistently less accurate when rendered to the screen than using borderRadius or drawing the path in a CGContextRef directly. Here are the results of all three methods: Notice that the third is poorly rendered, especially inside the stroke on the top and bottom. I have set the contentsScale property to [UIScreen mainScreen].scale . Here is my drawing code for these three circles. What’s missing to make the CAShapeLayer draw smoothly? @interface BCViewController () @end

touchesMoved drawing in CAShapeLayer slow/laggy

ぃ、小莉子 提交于 2019-11-28 01:15:38
问题 As was suggested to me in a prior StackOverflow question, I'm trying to improve my drawing method for letting my user draw lines/dots into a UIView. I'm now trying to draw using a CAShapeLayer instead of dispatch_async. This all works correctly, however, drawing into the CAShapeLayer continuously while touches are moving becomes slow and the path lags behind, whereas my old (inefficient I was told) code worked beautifully smooth and fast. You can see my old code commented out below. Is there

Draw circle with UIBezierPath

一个人想着一个人 提交于 2019-11-27 13:55:46
问题 I'm trying to draw a circle using UIBezierPath addArcWithCenter method : UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0., 0., 100., 100.)]; [bezierPath addArcWithCenter:center radius:0. startAngle:0 endAngle:2 * M_PI clockwise:YES]; CAShapeLayer *progressLayer = [[CAShapeLayer alloc] init]; [progressLayer setPath:bezierPath.CGPath]; [progressLayer setStrokeColor:[UIColor colorWithWhite:1. alpha:.2].CGColor]; [progressLayer setFillColor:[UIColor clearColor]

How to make my UIBezierPath animated with CAShapeLayer?

假装没事ソ 提交于 2019-11-27 12:51:57
I'm trying to animate a UIBezierPath and I've installed a CAShapeLayer to try to do it. Unfortunately the animation isn't working and I'm not sure any of the layers are having any affect (as the code is doing the same thing it was doing before I had the layers). Here is the actual code - would love any help. Draw2D is an implementation of UIView that is embedded in a UIViewController. All the drawing is happening inside the Draw2D class. The call to [_helper createDrawing... ] simply populates the _uipath variable with points. Draw2D.h defines the following properties: #define

UIImagePickerController editing view circle overlay

谁说胖子不能爱 提交于 2019-11-27 10:10:33
问题 I've been able to get pretty far with what I've been wanting to accomplish, and that's to replicate iOS's built in circular photo cropper for the built in contacts app. However, I'm stuck at trying to get my CAShapeLayers made correctly. I'm trying to make a transparent 320 px diameter circle and the rest of the view filled with an 0.9 alpha black background. The circle and rectangle are in the right place, but, the circle is not completely transparent like I need it to be. I'm lost as to how

How to draw a circle path with color gradient stroke

家住魔仙堡 提交于 2019-11-27 09:08:12
I want to draw a circle with color gradient stroke like the following picture, on both iOS and macOS: Is it possible to implement with CAShapeLayer or NSBezierPath / CGPath ? Or any other ways? In macOS 10.14 and later (as well as in iOS 12 and later), you can create a CAGradientLayer with a type of .conic , and then mask it with a circular arc. For example, for macOS: class GradientArcView: NSView { var startColor: NSColor = .white { didSet { setNeedsDisplay(bounds) } } var endColor: NSColor = .blue { didSet { setNeedsDisplay(bounds) } } var lineWidth: CGFloat = 3 { didSet { setNeedsDisplay

UIBezierPath Triangle with rounded edges

跟風遠走 提交于 2019-11-27 06:04:06
I have designed this code to generate a Bezier Path that is used as a path for a CAShapeLayer to mask a UIView (the view's height and width are variable) This code generates a triangle with sharp edges, but I would like to make it round cornered! I have spent a good 2 hours trying to work with addArcWithCenter... , lineCapStyle and lineJoinStyle etc but nothing seems to work for me. UIBezierPath *bezierPath = [UIBezierPath bezierPath]; CGPoint center = CGPointMake(rect.size.width / 2, 0); CGPoint bottomLeft = CGPointMake(10, rect.size.height - 0); CGPoint bottomRight = CGPointMake(rect.size

Applying a Gradient to CAShapeLayer

。_饼干妹妹 提交于 2019-11-26 19:24:09
问题 Does anyone have any experience in applying a Gradient to a CAShapeLayer? CAShapeLayer is a fantastic layer class, but it appears to only support solid fill coloring, whereas I'd like it to have a gradient fill (actually an animatable gradient at that). Everything else to do with CAShapeLayer (shadows, shapes, stroke color, animatable shape path) is fantastic. I've tried placing a CAGradientLayer inside a CAShapeLayer, or indeed setting the CAShapeLayer as the mask of the GradientLayer and