我創建了一個帶有半透明黑色背景的UIView
,以便放置在我的主應用視圖中。我在這裏瞄準的是在UIView
的某個地方創建一個切出的圓形形狀,其中沒有看到半透明的黑色背景,除了圓形區域外,在整個圖像上產生了黑色蒙板效果(這是爲了突出顯示該區域中的按鈕)。使用切出的圓掩蓋UIView
我已經設法使用CAShapeLayer
創建一個圓形的面具,但這有相反的效果(即其餘的視圖是清晰的,INSIDE圓是半透明的黑色。是半透明黑色以外的所有東西,然後是清晰的內容,下面是我使用的代碼,我將如何去使它以相反的方式工作?我的blackMask
是半透明的黑色視圖,我buttonCircle
是圓我想保持暢通。
也許我需要反轉的路徑,不知何故?
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGRect maskRect = buttonCircle.frame;
CGPathRef path = CGPathCreateWithEllipseInRect(maskRect, NULL);
maskLayer.path = path;
CGPathRelease(path);
blackMask.layer.mask = maskLayer;
編輯:現在嘗試這個,沒有看到任何面膜在所有與此一:
UIView *circularMaskView = [[UIView alloc] initWithFrame:buttonCircle.frame];
circularMaskView.backgroundColor = [UIColor greenColor];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGPathRef path = CGPathCreateWithEllipseInRect(buttonCircle.frame, NULL);
maskLayer.path = path;
CGPathRelease(path);
circularMaskView.layer.mask = maskLayer;
[blackMask addSubview:circularMaskView];
嘗試添加額外的視圖回到您的按鈕(同一幀)和它的子視圖添加到blackMask – santhu
這不會工作,按鈕本身不是一個圓圈。我只想圍繞它畫一個圓圈。 – Luke
我的意思是創建一個新的視圖,將它的背景顏色設置爲與buttonCircle.frame相同的這個新視圖的somevalue(非透明).set框架。將遮罩應用於此新視圖(path = buttonCircle.bounds)並將其作爲子視圖添加到blackMask。 – santhu