cashapelayer

How to disable TouchUpInside Action outside the boundary of button

你说的曾经没有我的故事 提交于 2019-12-06 15:53:32
This is my Xib. I just dragged a UIButton and changed its background color. I created a semi circle layer using this code let circlePath = UIBezierPath.init(arcCenter: CGPointMake(mybutton.bounds.size.width / 4, 0), radius: mybutton.bounds.size.height, startAngle: 0.0, endAngle: CGFloat(M_PI), clockwise: true) let circleShape = CAShapeLayer() circleShape.path = circlePath.CGPath mybutton.layer.mask = circleShape and this is my output. Its perfect as I want it. But the problem is that this button is clickable outside its rounded area(as per actuall shape of button). I want it to be clickable

Incorrect position of CAShapeLayer

◇◆丶佛笑我妖孽 提交于 2019-12-06 15:01:21
问题 I have a UIView called viewProgress . It is the white box in the image. I want a circular progress bar, which is the green circle in the image. The progress bar should stay within the white box, but as you can see it is way off. How do I make it stay inside the viewProgress ? Here you have my animation function: func animateView() { let circle = viewProgress // viewProgress is a UIView var progressCircle = CAShapeLayer() let circlePath = UIBezierPath(arcCenter: circle.center, radius: circle

animating strokeEnd in a CAShapeLayer using an animation block in Swift

陌路散爱 提交于 2019-12-06 10:50:31
问题 I am attempting to trace out the shape of a path that I've place into a CAShapeLayer. In this function, the points in the points array represent the vertices of a regular polygon. The animation isn't happening, though. It's just appearing, totally animated. Here is the code: private func drawShape (point: [(x: Double, y:Double)]) { let shapeLayer = CAShapeLayer() let shapePath = UIBezierPath() shapePath.moveToPoint(CGPoint(x:point[point.count-1].x, y:point[point.count-1].y)) for i in point {

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

CABasicAnimation - Setting start stroke position

萝らか妹 提交于 2019-12-06 01:31:22
问题 I'm animating the drawing of a basic circle. This works fine, except the animation begins drawing at the 3 o'clock position. Does anyone know how I can make it start at 12 o'clock? self.circle = [CAShapeLayer layer]; self.circle.fillColor = nil; self.circle.lineWidth = 7; self.circle.strokeColor = [UIColor blackColor].CGColor; self.circle.bounds = CGRectMake(0, 0, 200, 200); self.circle.path = [UIBezierPath bezierPathWithOvalInRect:self.circle.bounds].CGPath; [self.view.layer addSublayer:self

Adding border to mask layer

依然范特西╮ 提交于 2019-12-05 20:51:22
I'm trying to make a custom shape UIButton using mask layers and I was successful extension UIButton { func mask(withImage image : UIImage , frame : CGRect ){ let maskingLayer = CAShapeLayer() maskingLayer.frame = frame maskingLayer.contents = image.cgImage self.layer.mask = maskingLayer } } But I want to add a border (stroke) to the mask layer to indicate that this button was chosen. I tried adding a sub layer to the mask layer button.mask?.layer.borderColor = UIColor.black.cgColor button.mask?.layer.borderWidth = 4 but didn't work since the button shape is still rectangle. I know I can use

start and end angle of UIBezierPath?

徘徊边缘 提交于 2019-12-05 15:17:20
问题 I have coded as below for half circle in iOS using UIBezierPath and CAShapeLayer . clockWiseLayer = [[CAShapeLayer alloc] init]; CGFloat startAngle = -M_PI_2; CGFloat endAngle = M_PI + M_PI_2; CGFloat width = CGRectGetWidth(imageView.frame)/2.0f + 30; CGFloat height = CGRectGetHeight(imageView.frame)/2.0f +50; CGPoint centerPoint = CGPointMake(width, height); float radius = CGRectGetWidth(imageView.frame)/2+10; clockWiseLayer.path = [UIBezierPath bezierPathWithArcCenter:centerPoint radius

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

拈花ヽ惹草 提交于 2019-12-05 14:11:54
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 see the triangle stay longer. What can I do to get the triangle to stay on the screen, with it's

Drawing a line with Bezierpath using CAShapeLayer object

梦想的初衷 提交于 2019-12-05 03:23:01
I am making an image editor which can create different shapes objects like circle, triangle and square which can also be updated or removed. So I have used CAShapeLayer for creating shapes objects. Now I also want to draw a line on image which can also be updated or removed so I have used bezierpath and CAShapeLayer to create the line, it is working fine. BUT now the problem is that when I want to select any existing line it can be selected any where close to line tool because CAShapeLayer also set the fill region which will be a straight line from start point to end point. My question is that

Round Top Corners of a UIView in Swift

一个人想着一个人 提交于 2019-12-05 01:14:44
问题 I am trying to round top corners using below code func roundCorners(corners:UIRectCorner, radius: CGFloat) { let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) let maskLayer = CAShapeLayer() maskLayer.frame = self.bounds maskLayer.path = path.cgPath self.layer.mask = maskLayer } use myView.roundCorners(corners:[.topLeft, .topRight], radius: radius) But it's rounding one side of the view: this is in a tableView