我想在图像上创建“盲”效果,以便图像“盲”并出现。
有点像这种 JavaScript 过渡: https ://github.com/madrobby/scriptaculous - http://madrobby.github.io/scriptaculous/effect-blinddown/
蒙版设置正确,因为如果我手动更改它的位置,它会隐藏并显示其后面的图像,但它不会动画!它只是在动画的最终位置结束,你永远看不到它实际上是盲目的。
请帮忙!也许这不是达到盲目效果的最佳方式?
// 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 doesn't animate
[UIView commitAnimations];
[maskLayer release];
[boardLayer addSublayer:numberLayer];
[numberLayer release];