iOS 指定位置切圓角不生效問題

若是是在VC中操做,須要在viewDidLayoutSubviews方法裏spa

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
        CGFloat radius = 36; // 圓角大小
        UIRectCorner corner = UIRectCornerBottomLeft | UIRectCornerBottomRight;
        UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:self.backImageV.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.backImageV.bounds;
        maskLayer.path = path.CGPath;
        self.backImageV.layer.mask = maskLayer;
    
}

或者在其餘地方,給一個延時:code

//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        
//        CGFloat radius = 36; // 圓角大小
//        UIRectCorner corner = UIRectCornerBottomLeft | UIRectCornerBottomRight;
//        UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:self.backImageV.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
//        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//        maskLayer.frame = self.backImageV.bounds;
//        maskLayer.path = path.CGPath;
//        self.backImageV.layer.mask = maskLayer;
//    
//        
//    });
相關文章
相關標籤/搜索