//
//  PrizeDetailCardView.m
//  Open
//
//  Created by 雷俊博 on 2019/9/5.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "PrizeDetailCardView.h"
#import "Constants.h"

#define degreesToRadian(x) (M_PI * (x) / 180.0)

@interface PrizeDetailCardView ()

/** 遮罩 */

@property (nonatomic, strong) CAShapeLayer *maskLayer;

/** 路径 */

@property (nonatomic, strong) UIBezierPath *borderPath;

@end
@implementation PrizeDetailCardView
-(instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        // 初始化遮罩
        self.maskLayer = [CAShapeLayer layer];
        // 设置遮罩
        [self.layer setMask:self.maskLayer];
        // 初始化路径
        self.borderPath = [UIBezierPath bezierPath];
    }
    
    return self;
    
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //遮罩层frame
    self.maskLayer.frame = self.bounds;
    
    //设置path的起点
    [self.borderPath moveToPoint:CGPointMake(0, 10)];
    
    //左上角的圆角
    [self.borderPath addQuadCurveToPoint:CGPointMake(10, 0) controlPoint:CGPointMake(0, 0)];
    
    // 直线，到右上角
    
    [self.borderPath addLineToPoint:CGPointMake(self.bounds.size.width - 10, 0)];
    
    // 右上角的圆角
    
    [self.borderPath addQuadCurveToPoint:CGPointMake(self.bounds.size.width, 10) controlPoint:CGPointMake(self.bounds.size.width, 0)];
    
    // 直线，到右下角
    
    [self.borderPath addLineToPoint:CGPointMake(self.bounds.size.width, 213 * WIDTHRADIU)];
    
    [self.borderPath addArcWithCenter:CGPointMake(self.bounds.size.width , 213 * WIDTHRADIU + 6 *WIDTHRADIU ) radius:6 * WIDTHRADIU startAngle:degreesToRadian(-90) endAngle:degreesToRadian(-270) clockwise:NO];
    
    [self.borderPath addLineToPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height - 10)];
    
     [self.borderPath addQuadCurveToPoint:CGPointMake(self.bounds.size.width-10, self.bounds.size.height) controlPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height)];
    
     [self.borderPath addLineToPoint:CGPointMake(10, self.bounds.size.height )];
     [self.borderPath addQuadCurveToPoint:CGPointMake(0, self.bounds.size.height - 10) controlPoint:CGPointMake(0, self.bounds.size.height)];
     [self.borderPath addLineToPoint:CGPointMake(0, 213 * WIDTHRADIU + 10)];
    
    [self.borderPath addArcWithCenter:CGPointMake(0, 213 * WIDTHRADIU + 6 * WIDTHRADIU) radius:6 * WIDTHRADIU startAngle:degreesToRadian(90) endAngle:degreesToRadian(-90) clockwise:NO];
    
     [self.borderPath addLineToPoint:CGPointMake(0, 10)];
    
    self.maskLayer.path = self.borderPath.CGPath;
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
