cashapelayer

CAShapeLayer circle not showing on iPhone 6, but its working on iPhone 5 with the same code

≡放荡痞女 提交于 2019-12-12 03:04:03
问题 i made a simple circle programatically with cashapelayer in custom uiview class like this: class UserProfileCircleAnimated: UIView { private lazy var leftPhotoArc: CAShapeLayer = { let leftPhotoArc = CAShapeLayer() leftPhotoArc.lineWidth = 6 leftPhotoArc.strokeColor = UIColor.rgb(red: 232, green: 72, blue: 85, alpha: 1).cgColor leftPhotoArc.fillColor = nil leftPhotoArc.path = UIBezierPath(arcCenter: CGPoint(x: 25, y: 25), radius: 25 , startAngle: 2 * CGFloat(M_PI), endAngle: 0, clockwise:

Hide text with a shape mask Swift

拟墨画扇 提交于 2019-12-12 02:57:06
问题 I try to draw a triangle shape over the text, and to have the shape be painted where it intersects the text. When I try to apply the mask, text just disappears. Here's the code: import UIKit class ViewController: UIViewController { @IBOutlet weak var messageLabel: UILabel! let maskLayer = CAShapeLayer() override func viewDidLoad() { super.viewDidLoad() drawMask() messageLabel.layer.mask = maskLayer } func drawMask(){ let path = UIBezierPath() let xMsgLbl = messageLabel.center.x-80 let yMsgLbl

Rotate CAShapeLayer around center of UIView

谁说胖子不能爱 提交于 2019-12-11 19:26:45
问题 I am working on animation of CAShapeLayer. I am drawing quarter circle(refer image) which is in 1st quadrant(as per my knowledge). Now I want to rotate it 90 degree so it should fix in 2nd quadrant with animation on single tap gesture. I tried it but it is not fixing into 2nd quadrant. I want to rotate around center of UIView. Single tap gesture: - (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture { CGPoint touchPoint=[gesture locationInView:self]; NSArray* subLayerArray =

Value of type 'CAShapeLayer' has no member 'leadingAnchor'

白昼怎懂夜的黑 提交于 2019-12-11 16:57:26
问题 I have a circular shape which I use CAShapeLayer to draw. Now I want to constraint my button to the leading anchor of the layer but then I get this error "Value of type 'CAShapeLayer' has no member 'leadingAnchor'". How can I fix this. Code: btnSMSIcon.leadingAnchor.constraint(equalTo: shapeLayer.leadingAnchor, constant: 60).isActive = true 回答1: AutoLayout deals with views, not layers. If you want to include a layer in your AutoLayout, attach the layer to a view. (You can create a custom

Flickering in CABasicAnimation for rotation

懵懂的女人 提交于 2019-12-11 12:51:46
问题 I am trying to rotate a CAShapeLayer by an angle from its current angle whenever a button is pressed. I am using delegate function animationDidStop to set the transform of the layer during end of animation, since I have noticed animation only changes the transform of the presentation layer and not the layer in itself. But there are random flickering in the animation which seems to be during the end of the animation when the animation is complete due to layer going back to its previous

CAShapeLayer doesn't rotate with CGAffineTransformRotate on devices older than iPhone 5s

♀尐吖头ヾ 提交于 2019-12-11 11:14:22
问题 I'm creating simple Arc type chart like this: - (void)drawRect:(CGRect)rect { CGFloat lineWidth = 18.5f; CGFloat margin = 11; CAShapeLayer *circleLayer = [CAShapeLayer layer]; [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect: CGRectMake(margin + lineWidth/2, margin + lineWidth/2, CGRectGetWidth(rect) - margin * 2 - lineWidth, CGRectGetWidth(rect)- margin * 2 - lineWidth) ] CGPath]]; [circleLayer setStrokeColor:[_fillColor CGColor]]; [circleLayer setFillColor:[[UIColor clearColor]

How can i draw smooth freehand drawing using shapelayer and bezierpath over an image

纵然是瞬间 提交于 2019-12-11 06:59:21
问题 let path = UIBezierPath() shapeLayer.strokeColor = UIColor.blue.cgColor shapeLayer.lineWidth = 3 path.move(to: startPoint) path.addLine(to: point) shapeLayer.lineJoin = kCALineJoinRound shapeLayer.path = path.cgPath tempImage.layer.addSublayer(shapeLayer) I am using the above code. Calling the above code each tome the touch is moved. I am not getting a continuous drawing . only the final portion of my drawing is visible.Is there anything i am missing here. 回答1: I achieved a smooth drawing

How to make universal round draws (with lineDashPattern) with UIbezierPath on Swift

*爱你&永不变心* 提交于 2019-12-11 04:29:57
问题 I'm about to make a universal Tuner app but when I try to draw an Analog meter it gets messed on different devices. Maybe it's very hardcoded.. Check this: The labels are under the same UIView too. Check the code to draw these paths: override func draw(_ rect: CGRect) { let center = CGPoint(x:bounds.width/2, y: bounds.height) var radius: CGFloat = max(bounds.width, bounds.height+50) // Define the thickness of the arc. let arcWidth: CGFloat = 1 let startAngle: CGFloat = π let endAngle: CGFloat

CAShapeLayer detect touch during animation Swift

三世轮回 提交于 2019-12-11 03:17:59
问题 I can detect a touch of a CAShapeLayer like this (touchesEnded): let touchLocation : CGPoint = (touch as! UITouch).locationInView(self.view) for shape in shapes{ if CGPathContainsPoint(shape.path, nil, touchLocation, false){ print("Layer touch") } } And I can animate the path of a CAShapeLayer like this: let newShapePath = UIBezierPath(arcCenter: toPoint, radius: 20, startAngle: CGFloat(0), endAngle: CGFloat(M_PI * 2), clockwise: true).CGPath // animate the `path` let animation =

Recreate Apple Watch fitness tracker ‘progress’ bar - gradient on CAShapeLayer stroke

老子叫甜甜 提交于 2019-12-11 02:16:59
问题 I'm writing an app that could make good use of the Apple Watch's fitness tracker design, here: So far, I've created the basic outline which is just a CAShapeLayer with a CGPath of an ellipse. I use strokeStart and strokeEnd to animate the progress. My problem comes when applying a gradient to the outline. How do I apply a gradient like above to the stroke of a CGPath? 回答1: The cleanest way to do this without having to drop down to Core Graphics or GL is to create a layer containing the angle