Search code examples
iosobjective-cuibezierpathcashapelayercgpath

frame.origin and bounds.size of CAShapeLayer are set to 0


With the following Code I get always the values of shapeLayer.frame.origin.x = 0 shapeLayer.frame.origin.y =0 shapeLayer.bounds.size.width = 0 shapeLayer.bounds.size.height=0 Did anyone get an Idea? thank you for your answer.

-(void) makeShape {
UIBezierPath * path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(408.000000,230.000000) ];
[path addCurveToPoint:CGPointMake(365.000000,251.000000) controlPoint1:CGPointMake(399.399994,236.000000) controlPoint2:CGPointMake(365.000000,239.000000) ];
[path addCurveToPoint:CGPointMake(309.000000,287.000000) controlPoint1:CGPointMake(353.799988,252.000000) controlPoint2:CGPointMake(309.000000,252.000000) ];
[path addLineToPoint:CGPointMake(236.000000,321.000000) ];
[path addLineToPoint:CGPointMake(207.000000,384.000000) ];
[path addCurveToPoint:CGPointMake(157.000000,416.000000) controlPoint1:CGPointMake(197.000000,388.000000) controlPoint2:CGPointMake(157.000000,390.000000) ];
[path addLineToPoint:CGPointMake(90.000000,489.000000) ];
[path addCurveToPoint:CGPointMake(49.000000,566.000000) controlPoint1:CGPointMake(81.800003,490.000000) controlPoint2:CGPointMake(49.000004,506.000000) ];
[path addCurveToPoint:CGPointMake(19.000000,640.000000) controlPoint1:CGPointMake(35.400002,567.000000) controlPoint2:CGPointMake(18.999998,568.000000) ];
[path addLineToPoint:CGPointMake(365.000000,800.000000) ];
[path addLineToPoint:CGPointMake(415.000000,700.000000) ];
[path  closePath];
CAShapeLayer * shapeLayer = [CAShapeLayer layer];
shapeLayer.strokeColor = [[UIColor blackColor] CGColor];
shapeLayer.fillColor = [UIColor grayColor].CGColor;
shapeLayer.lineWidth = 1.5f;
shapeLayer.lineJoin = kCALineJoinRound;
shapeLayer.path = path.CGPath;
[self.view.layer addSublayer:shapeLayer];
float x= shapeLayer.frame.origin.x;
float y = shapeLayer.frame.origin.y;
float w= shapeLayer.bounds.size.width;
float h = shapeLayer.bounds.size.height;
NSLog(@"Point(%f,%f)",x,y);
NSLog(@"Size(%f,%f)",w,h);
}

Solution

  • I figure it out. it's just to set the property bounds with the path.bounds.

    but this shrinks the shape and modify it's position when no bounds are set