简体   繁体   中英

move uiimage inside a bezier curve

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];
maskLayer.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM