开发者

move uiimage inside a bezier curve

开发者 https://www.devze.com 2023-04-12 22:35 出处:网络
I have drawn a circle using bezier curve, I am using this circle as a mask to a uiimage view.Now, how can i move the image inside the circle without moving the circle using touches.

I have drawn a circle using bezier curve, I am using this circle as a mask to a uiimage view. Now, how can i move the image inside the circle without moving the circle using touches. here is my code.

       CAShapeLayer *maskLayer = [CAShapeLayer layer];

aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(220, 220)
                                       radius:170
                                   startAngle:0
                                     endAngle:DEGREES_TO_RADIANS(360)
                                    clockwise:YES];

maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
mask开发者_高级运维Layer.path = [aPath CGPath];

maskLayer.masksToBounds=YES;

imageView1.layer.mask = maskLayer;

[self.view addSubview:imageView1];


The coordinates of the mask is the same as the coordinates of your views layer = it moves along with the view.

You can add the image inside another view and mask that view instead. Then you can move the image inside the other view and the mask will stay the same.

Alternatively (but really the same solution) you could keep the mask on that layer and add a sublayer with the image and move that instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消