Track animation on CALayer with mask

I want to create a “blind rotation” effect on the image so that it “dazzles” and displays.

It seems like this JavaScript transition: https://github.com/madrobby/scriptaculous - http://madrobby.imtqy.com/scriptaculous/effect-blinddown/

The mask is set correctly, because if I manually change its position, it hides and shows the image behind it, but it does not animate! He just finds himself in the final position of the animation, and you will never see him blind.

Please help! Maybe this is not the best way to achieve the effect of blind fluff?

// create a new layer
CALayer *numberLayer = [[CALayer alloc] init];

// render the number "7" on the layer
UIImage *image = [UIImage imageNamed:@"number-7.png"];
numberLayer.contents = (id) [image CGImage];
numberLayer.bounds = CGRectMake(0, 0, image.size.width, image.size.height); // width and height are 50
numberLayer.position = position;

// create a new mask that is 50x50 the size of the image
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGMutablePathRef path = CGPathCreateMutable();

CGPathAddRect(path, nil, CGRectMake(0, 0, 50, 50));

[maskLayer setPath:path];
[maskLayer setFillColor:[[UIColor whiteColor] CGColor]];

[theLayer setMask:maskLayer];

[maskLayer setPosition:CGPointMake(0, 0)]; // place the mask over the image

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0];
[maskLayer setPosition:CGPointMake(0, 50)]; // slide mask off the image
// this should shift the blind away in an animation
// but it does not animate
[UIView commitAnimations]; 
[maskLayer release];

[boardLayer addSublayer:numberLayer];
[numberLayer release];
+4
1

, . CALayer contentRect. " " . , contentRect , . Core Animation .

, , , :

  • contentsRect " ", 0.0 1.0 ( 0.0 , 1.0 ).

  • UIView. , 0.0, 0.0, , . , .

  • , , masksToBounds=YES.

0

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


All Articles