Holding a CAShapeLayer mask static during animation

I am trying to rotate a UIImageView in a round mask (which is set using myImageView.layer.mask). The problem is that whenever I try to rotate the specified UIImageView, the mask rotates with it. Here is the code.

Mask Setting:

UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(0, - 169) radius:191 startAngle:0.0 endAngle:2*M_PI clockwise:YES]; CAShapeLayer *shapeLayer = [CAShapeLayer layer]; [shapeLayer setFrame:myImageView.bounds]; [shapeLayer setPath:[path CGPath]]; myImageView.layer.mask = shapeLayer; 

Animation:

 [UIView animateWithDuration:kRotationTime animations:^(void){ myImageView.transform = CGAffineTransformMakeRotation(angle); }]; 

And that, in principle, everything is there. UIImageView rotating around its own center in a fixed position circular mask is the desired effect. There may be another way to structure the hierarchy of views so that myImageView and mask are siblings, but I have no luck with this route.

+4
source share
1 answer

Place the image view in an optional regular UIView view. Set the layer mask to the supervisor. Animation image.

+8
source

Source: https://habr.com/ru/post/1413492/


All Articles