cashapelayer

Frame and Bounds of CAShapeLayer

删除回忆录丶 提交于 2019-12-18 13:19:19
问题 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

Scale CGPath to Fit UIVIew

妖精的绣舞 提交于 2019-12-18 12:19:29
问题 I need to know how I can scale down or up CGPath so it can fit UIView? Set the background color to yellow, To see the view clearly self.frame = CGRectMake(0, 0, 181, 154); self.backgroundColor = [UIColor yellowColor]; Draw CAShapeLayer CAShapeLayer *shape = [CAShapeLayer layer]; shape.path = aPath; shape.strokeColor = [[UIColor blueColor] CGColor]; shape.lineWidth = 5; shape.fillColor = [[UIColor clearColor] CGColor]; [self.layer addSublayer:shape]; Then I get This: What I want is this: Thank

An easy way to draw a circle using CAShapeLayer

大憨熊 提交于 2019-12-18 11:01:35
问题 In questions like How to draw a smooth circle..., ...Draw Circle... and ...draw filled Circles the question and answer is very broad, contains lots of unnecessary steps and the methods used isn't always the easiest to re-create or manage. What is an easy way to draw a circle and add it to my UIView ? 回答1: An easy way to draw a circle is to create a CAShapeLayer and add a UIBezierPath . objective-c CAShapeLayer *circleLayer = [CAShapeLayer layer]; [circleLayer setPath:[[UIBezierPath

An easy way to draw a circle using CAShapeLayer

限于喜欢 提交于 2019-12-18 11:01:16
问题 In questions like How to draw a smooth circle..., ...Draw Circle... and ...draw filled Circles the question and answer is very broad, contains lots of unnecessary steps and the methods used isn't always the easiest to re-create or manage. What is an easy way to draw a circle and add it to my UIView ? 回答1: An easy way to draw a circle is to create a CAShapeLayer and add a UIBezierPath . objective-c CAShapeLayer *circleLayer = [CAShapeLayer layer]; [circleLayer setPath:[[UIBezierPath

iOS CAShapeLayer、CADisplayLink 实现波浪动画效果

落爺英雄遲暮 提交于 2019-12-18 07:11:12
iOS CAShapeLayer、CADisplayLink 实现波浪动画效果 效果图 代码已上传 GitHub: https://github.com/Silence-GitHub/CoreAnimationDemo 可以自定义波浪高度、宽度、速度、方向、渐变速度、水的深度等参数。 实现原理 波浪的形状绘制在 CAShapeLayer 上。通过 CADisplayLink 与屏幕刷新频率同步,每次刷新都绘制新的波浪,并改变小船的位置和角度。另外,水和天空的颜色是渐变的,由 CAGradientLayer 实现,其中,显示水的 CAGradientLayer 需要有波浪形状的 CAShapeLayer 的遮罩(mask)。 CAShapeLayer CAShapeLayer 的属性 path (CGPath)就是图层要显示的形状。把波浪的形状绘制出来,赋值给此属性即可。 CADisplayLink 创建 CADisplayLink,相应的 target 实现屏幕刷新时要调用的方法。把 CADisplayLink 加入 RunLoop 中。通过 isPaused 属性控制 CADisplayLink 是否暂停(target 是否调用方法) private var waveLink: CADisplayLink? waveLink = CADisplayLink(target:

Animating CAShapeLayer size change

随声附和 提交于 2019-12-17 22:34:36
问题 I am drawing a circle, with an initial radius of 200 self.circle = [CAShapeLayer layer]; self.circle.fillColor = nil; self.circle.strokeColor = [UIColor blackColor].CGColor; self.circle.lineWidth = 7; self.circle.bounds = CGRectMake(0, 0, 2 * radius, 2 * radius); self.circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.radius, self.radius) Can anyone please tell me how to animate a change to a radius of 100? 回答1: This is how I ended up doing it: UIBezierPath *newPath =

Mask a UIView with a cut-out circle

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 22:23:49
问题 I’ve created a UIView with a semi-transparent black background to sit across my main app’s view. What I’m aiming for here is to create a cut-out circle shape somewhere in that UIView where the semi-transparent black background is not seen, giving the effect of a black mask over the whole image except the circular area (this is to highlight a button in that area). I’ve managed to use CAShapeLayer to create a circular mask, but this has had the opposite effect (i.e. the rest of the view is

Custom image mask in iOS

雨燕双飞 提交于 2019-12-17 17:46:19
问题 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

How to draw a smooth circle with CAShapeLayer and UIBezierPath?

我们两清 提交于 2019-12-17 17:23:48
问题 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

How to animate CAShapeLayer path and fillColor

偶尔善良 提交于 2019-12-17 15:44:23
问题 How to animate CAShapeLayer path and fillColor? How to animate strokeEnd to show the path being drawn? and how to animate fillColor? 回答1: To animate path //setup the CAShapeLayer myShapeLayer.strokeColor = [[UIColor blueColor] CGColor]; myShapeLayer.lineWidth = 5; myShapeLayer.fillColor = [[UIColor yellowColor] CGColor]; //Display it! [self.view.layer addSublayer:myShapeLayer]; //Animate path CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; pathAnimation