[英]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.