cashapelayer

Swift: Add image to CAShapeLayer

余生颓废 提交于 2019-12-01 10:11:31
问题 I have a CAShapeLayer with a fill color, and want to add an icon in the center of this shape: var shape = CAShapeLayer() shape.fillColor = UIColor(white: 0.90, alpha: 1).CGColor var image = UIImage(named: "some_image") shape.contents = image?.CGImage This code does compile and does show the grey shape- but no image. :( I looked into these posts, but I can't cast the CGImage like they do. add UIImage in CALayer and Display an image or UIImage with a plain CALayer Is there another way? Or a

Get position of path at time

ぐ巨炮叔叔 提交于 2019-12-01 06:00:58
is there a nice way to calculate the position of a path (CGPath or UIBezierPath) at a given time (from 0 to 1)? Using CAShapeLayer for example, one can create an animated stroke end. I want to know the position of that stroke end at arbitrary times. Thanks in advance, Adrian You can definitely base your approach on the CADisplayLink and a tracking layer. However, if you don't mind doing a little bit of math on your own, the solution is not too complicated. Plus, you wont have to depend on setting up a display link and extra layers. In fact, you dont even have to depend on QuartzCore. The

Create a UIView with only one diagonal side

六眼飞鱼酱① 提交于 2019-11-30 20:18:31
I need to create a UIView that has the left border inclined with 45 degrees I was wondering,is there a way to acheive this programmatically? Does CATransform3D help me in this case since it’s not really a “3D rotation”? Edit Here's an image explaining more my needed output Fogmeister If you just want the shape with no content then you can create a CAShapeLayer and add it to your view's layer. (In fact you can also put content in there using this method but you'll need to alter it a bit). CAShapeLayer *layer = [CAShapeLayer layer]; UIBezierPath *path = [UIBezierPath bezierPath]; [path

iOS: CAShape Layer Path Transformation

ぐ巨炮叔叔 提交于 2019-11-30 16:51:31
I have used CAShape Layer before doing basic transformation on paths - from a smaller circle into a larger circle. Good enough, but then I tried to transform a triangle into a circle; it worked, but the transformation is weird. Other words, from one shape to another, it "flips", "twists" before the final shape is formed. With the same shapes, there is no problem - from a circle to a circle - but with different shapes, the transformation is weird. I wonder if this is the expected way? Or is there other tricks or workarounds where we can smoothly and proportionally transform one shape into

UIView Layer Mask Animate

蓝咒 提交于 2019-11-30 14:31:02
I am trying to animate the mask layer on a UIView. Basically this code displays the image below: let bounds: CGRect = self.manualWBMaskView!.bounds let maskLayer: CAShapeLayer = CAShapeLayer() maskLayer.frame = bounds maskLayer.fillColor = UIColor.blackColor().CGColor let screenWith : CGFloat = UIScreen.mainScreen().bounds.width let roundedRectFrame : CGRect = CGRectMake(self.manualWBMaskView!.bounds.midX - (screenWith/4), self.manualWBMaskView!.bounds.midY - (screenWith/4), screenWith/2, screenWith/2) let path: UIBezierPath = UIBezierPath(roundedRect:roundedRectFrame, cornerRadius:10 ) path

how to draw CALayer with line path like simulate eraser effect?

感情迁移 提交于 2019-11-30 10:51:30
I want to simulate eraser effect with touch event to show a image that behind something block on top, eg, gray color; Something like that: I have find for a long time for the solution but I can't do it well. following is my custom view code: CustomView.m: -(id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self setup]; } return self; } -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setup]; } return self; } -(void)setup { [self setMultipleTouchEnabled:NO]; [self setBackgroundColor:[UIColor darkGrayColor]]; self

Frame and Bounds of CAShapeLayer

好久不见. 提交于 2019-11-30 08:57:16
I am working on CAShapeLayer .And trying to draw non-linear path.I want to set frame to CAShapeLayer .So i can use CGPathGetPathBoundingBox method to get frame from CGPathRef . Here is code : CGMutablePathRef path = CGPathCreateMutable(); CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100, (0), (M_PI_2), NO); CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100-50, (M_PI_2), (0), YES); CGPathCloseSubpath(path); CAShapeLayer* arcLayer = [[CAShapeLayer alloc]init]; arcLayer.path = path; arcLayer.frame = CGPathGetPathBoundingBox(path); arcLayer.bounds =

How to draw line on Image Pattern exactly

元气小坏坏 提交于 2019-11-30 07:21:30
I have a UIImageView. Inside that I am drawing a line wit user touch event. Problem is that a line can be drawn anywhere in UIImageview , but I like to draw line with image pattern only. For example, look at this image. I need to draw line on image pattern only. This is my code: -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; touchPoint = [touch locationInView:self.imgColor]; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)]; [path addLineToPoint:CGPointMake

Create a UIView with only one diagonal side

旧时模样 提交于 2019-11-30 04:22:33
问题 I need to create a UIView that has the left border inclined with 45 degrees I was wondering,is there a way to acheive this programmatically? Does CATransform3D help me in this case since it’s not really a “3D rotation”? Edit Here's an image explaining more my needed output 回答1: If you just want the shape with no content then you can create a CAShapeLayer and add it to your view's layer. (In fact you can also put content in there using this method but you'll need to alter it a bit).

clip-masking uiview with CAShapeLayer and UIBezierPath

自闭症网瘾萝莉.ら 提交于 2019-11-30 03:57:45
问题 I have a problem clipping a view using CAShapeLayer-UIBezierPath , I want to clip the content but I end up getting a stroke (frame) with that UIBezierPath , This is my code UIBezierPath *path2Path = [UIBezierPath bezierPath]; [path2Path moveToPoint:CGPointMake(206.745, 0)]; [path2Path addLineToPoint:CGPointMake(206.745, 97.613)]; [path2Path addLineToPoint:CGPointMake(0, 97.613)]; [path2Path addLineToPoint:CGPointMake(0, 0)]; [path2Path addLineToPoint:CGPointMake(87.28, 0)]; [path2Path