繁体   English   中英

动画UIView和蒙版

[英]Animating UIView and Mask

我有一个UIImageView基本上是痣。 我希望这颗痣从洞中弹出。 因此,实际上我要记住的是,我将在孔下方的某些点上创建一个痣,并在其上设置蒙版,然后为图像视图设置动画,使其看起来像从孔中弹出。 因此,按照这种想法,我写下了以下代码:

    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    CGRect maskRect = _moleIcon.frame;
    CGPathRef path = CGPathCreateWithRect(maskRect, NULL);
    maskLayer.path = path;
    CGPathRelease(path);
    _moleIcon.layer.mask = maskLayer;
    [UIView animateWithDuration:2.0 animations:^(void){
        _moleIcon.transform=CGAffineTransformMakeTranslation(0, 50);
    }];

但问题是,遮罩本身似乎与实际的UIImageView一起移动。 任何帮助将不胜感激。

在此处输入图片说明

尝试使用2个UIView,只需将maskView放在最前面:

[superview bringSubviewToFront:maskView];

并为蒙版视图设置背景颜色和alpha属性,

maskView.backgroundColor = [UIColor blackColor];
maskView.alpha = 0.8;

现在您可以直接移动2视图。

但更好的方法是将2个视图添加到其他视图-容器中,然后旋转一个视图。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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