如果想把UIView挖空一块,使用遮罩图。 效果图如下:

image

示例代码如下:

1
2
3
4
5
6
7
8
9
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    CALayer *mask = [CALayer layer];
    mask.frame = self.maskView.bounds;
    mask.contents = (id)[[UIImage imageNamed:@"mask"] CGImage];
    _maskView.layer.mask = mask;
    _maskView.layer.masksToBounds = YES;
}

代码见链接