コードベース。私はこれがあなたが望むものであるかどうかはわかりません。
ボタンのUIBezierPathをmaskPathに追加するだけです。 このようなコード(コード上の塩基)
const NSInteger kHoleSize = 100;
UIButton *mapCardsButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kHoleSize, kHoleSize)];
[mapCardsButton setTitle:@"BUTTON" forState:UIControlStateNormal];
mapCardsButton.backgroundColor = [UIColor redColor];
[self.view addSubview:mapCardsButton];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:self.view.bounds];
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:self.view.center
radius:kHoleSize/2.0f
startAngle:0.0f
endAngle:2.0f*M_PI
clockwise:NO];
UIBezierPath *buttonPath = [UIBezierPath bezierPathWithRect:mapCardsButton.frame];
[circlePath appendPath:buttonPath];
[maskPath appendPath:circlePath];
[maskPath setUsesEvenOddFillRule:YES];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = maskPath.CGPath;
maskLayer.fillRule = kCAFillRuleEvenOdd;
maskLayer.fillColor = [UIColor blackColor].CGColor;
maskLayer.opacity = 0.9;
[self.view.layer addSublayer:maskLayer];
[insertSublayer self.view.layer:勾配atIndex:0]; –
このコードを追加した後、UIViewがアルファなしで黒くなり、maskLayerのアニメーションがもう機能しなくなりました。 – Sergio
あなたはフルビューをマスクし、現在表示されているフルボタンフレームのみを表示したい – HardikDG