cashapelayer

Setting toValue for CAShapeLayer animation from UICollectionView cellForItemAt indexPath

只谈情不闲聊 提交于 2019-12-24 20:23:15
问题 I have the following parts: - My main view is a UIViewController with a UICollectionView - The cell for the UICollectionView - A subclass of the UIView to build a CAShapeLayer with an CABasicAnimation In my main view I have a UICollectionView which renders a bunch of cells with labels etc. It also is showing a progress graph. In my subclass ProgressCirclePath() I am drawing a CAShapeLayer which is acting as the progress graph rendered in each cell of my UICollectionView. I have been able to

Is it possible to add a background Image to a CAShape? (iPhone)

烂漫一生 提交于 2019-12-24 19:11:21
问题 I am trying to distort an image in an arbitrary way, following for example a bezier shape. I have used CAShapeLayer to create the shape, but then it seems that setting its contents to an Image does not work. How can I have the image distorted following that shape? Is it even possible? Thank you! 回答1: This is currently not possible. I would suggest filing a radar (http://bugreport.apple.com) if you think this should be supported. See also: Can a CGImage be added to the contents property of a

CAShapeLayer custom property is nil when drawInContext

半城伤御伤魂 提交于 2019-12-24 09:16:08
问题 I denfined a custom layer,and declare a custom property,but it's not work when animation in -(void)drawInContext:(CGContextRef)ctx method here is some code: @interface ZBBProgressLayer : CAShapeLayer @property (nonatomic, assign) CGFloat progress; @property(nullable) CGColorRef progressColor; @end @implementation ZBBProgressLayer + (BOOL)needsDisplayForKey:(NSString *)key{ if ([key isEqualToString:@"progress"]/*progress 属性变化时,重绘*/) { return YES; } return [super needsDisplayForKey:key]; } -

How to apply multiple masks to UIView

北城余情 提交于 2019-12-24 00:08:31
问题 I have a question about how to apply multiple masks to a UIView that already has a mask. The situation: I have a view with an active mask that creates a hole in its top left corner, this is a template UIView that is reused everywhere in the project. Later in the project I would like to be able to create a second hole but this time in the bottom right corner, this without the need to create a completely new UIView. The problem: When I apply the bottom mask, it of course replaces the first one

How to scale a CAShapeLayer

房东的猫 提交于 2019-12-23 11:57:48
问题 In swift I've successfully made an animated bezier path which is contained inside a CAShapeLayer . My only problem is implementing it onto other screen sizes. Does anybody know how I can scale the CAShapeLayer with the path inside of it? i.e. make it half the original size. 回答1: Use this function: var shapelayer:CAShapeLayer shapelayer.transform = CATransform3DMakeScale(, ,) 来源: https://stackoverflow.com/questions/29740090/how-to-scale-a-cashapelayer

Trying to draw dashed border for UITableViewCell

馋奶兔 提交于 2019-12-23 06:13:08
问题 I'm trying to draw a dashed bottom border to UITableViewCells with the following code: func addDashedBottomBorder(to cell: UITableViewCell) { let width = CGFloat(2.0) let dashedBorderLayer: CAShapeLayer = CAShapeLayer() let frameSize = cell.frame.size let shapeRect = CGRect(x: 0, y: frameSize.height, width: frameSize.width*2, height: 1) dashedBorderLayer.bounds = shapeRect dashedBorderLayer.position = CGPoint(x: 0, y: frameSize.height) dashedBorderLayer.strokeColor = UIColor.lightGray.cgColor

Swift-animate CAshapeLayer stroke color

情到浓时终转凉″ 提交于 2019-12-22 12:20:44
问题 I'm trying to find a way to animate the color of the stroke that I am creating circleLayer = CAShapeLayer() circleLayer.path = circlePath.CGPath circleLayer.lineCap = kCALineCapRound circleLayer.fillColor = UIColor.clearColor().CGColor CABasicAnimation fill = CABasicAnimation. circleLayer.strokeColor = UIColor(red: 0.4, green: 1.0, blue: 0.2, alpha: 0.5).CGColor circleLayer.lineWidth = 20.0; circleLayer.lineJoin = kCALineJoinRound // Don't draw the circle initially circleLayer.strokeEnd = 0.0

CAShapeLayer path disappears after animation - need it to stay in the same place

戏子无情 提交于 2019-12-22 08:11:26
问题 Thanks to some help on StackOverflow, I am currently animating a path in CAShapeLayer to make a triangle that points from a moving sprite to another moving point on the screen. Once the animation completes, the triangle disappears from the screen. I am using very short durations because this code is being fired every .1 of second for each of the sprites. The result is the red triangle tracks correctly, but it rapidly flashes or isn't there entirely. When I crank up the the duration, I can the

Transforming a CAShapelayer to a specific size in swift

自闭症网瘾萝莉.ら 提交于 2019-12-21 22:37:21
问题 I'm trying to make a CAShapeLayer with a bezier path in it expand with a view (which is animated, of course). I am aware that I could change the size of the path with CATransform3DMakeScale(, , ) But this won't allow me to make the path an exact size (in points). Does anybody know how to do this? 回答1: You would do this using good old fashioned math. Simple solution To phrase your question differently: you have something of one size (the path/shape layer), and you want to scale it so that it

How to draw Arc with curved edge in iOS?

冷暖自知 提交于 2019-12-21 19:57:29
问题 In one of my application, I am trying to draw a gradient arc with rounded edges. Like the following image. This is what I have done so far using the following code. -(void)startArc { UIBezierPath *roundedArc = [self arcWithRoundedCornerAt:centerPoint startAngle:DEGREES_TO_RADIANS(-90) endAngle:DEGREES_TO_RADIANS(90) innerRadius:width-20 outerRadius:width cornerRadius:0]; CAShapeLayer *mask = [CAShapeLayer new]; [mask setPath:roundedArc.CGPath]; [mask setFrame:_outerView.bounds]; [mask