0

I have a UIView with an image drawn in it. And I drawed a bezier path on the uiview, and I tried to mask the uiview according to the bezier path, it works but the mask get shifted down all the time.

Here are the images:

And I drew a bezier path on the view:

The final result, after I the apply mask is:

Here is what I tried:

-(void)sendBezierPath:(UIBezierPath *)path{
    //this method gets hit after the bezier path gets interesected
    _shapeLayer=[[CAShapeLayer alloc]init];
    _shapeLayer.frame=imageUIView.frame;
    _shapeLayer.path=path.CGPath;
    imageUIView.layer.mask=_shapeLayer;

   }

As you can see, I didn't give any position to the shape layer, but after the mask when I print the shape layer position, it gave me the value (160,294).

I can move the shape layer to get the current position,by

     //  shapeLayer.position=CGPointMake(160, 100);

but I want to know why it gets to the wrong position. It moved almost 40px down.

jscs
  • 63,694
  • 13
  • 151
  • 195
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • 2
    `_shapeLayer.frame = imageUIView.bounds;`. It's like adding a subview. Its coordinates interpretations differs if it read from its superview (by default), or a super super view, etc. – Larme Dec 16 '15 at 21:11
  • 2
    Actually to be totally correct it should be `_shapeLayer.frame = imageUIView.layer.bounds`, but the two should be equivalent. – Duncan C Dec 16 '15 at 21:20
  • @Larme yeah!!! It worked !!! Thanks!! – Teja Nandamuri Dec 16 '15 at 21:25

0 Answers0