萤石云 iOSSDK,移植跨平台相关工程
JLChen
2021-08-06 edc0f0a0439f9e5a11593e21a4779fa6dbcbe49d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
//  EZQRView.m
//  EZOpenSDKDemo
//
//  Created by DeJohn Dong on 15/10/29.
//  Copyright © 2015年 Ezviz. All rights reserved.
//
 
#import "EZQRView.h"
 
@implementation EZQRView
 
- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupUI];
}
 
- (void)layoutSubviews {
    [super layoutSubviews];
    [self setupUI];
}
 
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    
    //整个二维码扫描界面的颜色
    CGSize screenSize = self.bounds.size;
    CGRect screenDrawRect = CGRectMake(0, 0, screenSize.width,screenSize.height);
    
    //中间清空的矩形框
    CGRect clearDrawRect = CGRectMake(screenDrawRect.size.width / 2 - self.clearSize.width / 2,
                                      screenDrawRect.size.height / 3 - self.clearSize.height / 2,
                                      self.clearSize.width,self.clearSize.height);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    [self addScreenFillRect:ctx rect:screenDrawRect];
    
    [self addCenterClearRect:ctx rect:clearDrawRect];
    
    [self addCornerLineWithContext:ctx rect:clearDrawRect];
}
 
 
#pragma mark - Custom Methods
 
- (void)setupUI
{
    
}
 
#pragma mark - Draw Methods
 
- (void)addScreenFillRect:(CGContextRef)ctx rect:(CGRect)rect
{
    
    CGContextSetRGBFillColor(ctx, 40/255.0, 40/255.0, 40/255.0, 0.5);
    CGContextFillRect(ctx, rect);   //draw the transparent layer
}
 
- (void)addCenterClearRect:(CGContextRef)ctx rect:(CGRect)rect {
    
    CGContextClearRect(ctx, rect);  //clear the center rect  of the layer
}
 
- (void)addCornerLineWithContext:(CGContextRef)ctx rect:(CGRect)rect{
    
    //画四个边角
    CGContextSetLineWidth(ctx, 3);
    CGContextSetRGBStrokeColor(ctx, 255/255.0, 84/255.0, 0/255.0, 1);//绿色
    
    //左上角
    CGPoint pointsTopLeftA[] = {
        CGPointMake(rect.origin.x + 0.7, rect.origin.y),
        CGPointMake(rect.origin.x + 0.7 , rect.origin.y + 15)
    };
    
    CGPoint pointsTopLeftB[] = {
        CGPointMake(rect.origin.x, rect.origin.y + 0.7),
        CGPointMake(rect.origin.x + 15, rect.origin.y + 0.7)
    };
    [self addLine:pointsTopLeftA pointB:pointsTopLeftB ctx:ctx];
    
    //左下角
    CGPoint pointsBottomLeftA[] = {
        CGPointMake(rect.origin.x + 0.7, rect.origin.y + rect.size.height - 15),
        CGPointMake(rect.origin.x + 0.7, rect.origin.y + rect.size.height)
    };
    CGPoint pointsBottomLeftB[] = {
        CGPointMake(rect.origin.x , rect.origin.y + rect.size.height - 0.7),
        CGPointMake(rect.origin.x + 15.7, rect.origin.y + rect.size.height - 0.7)
    };
    [self addLine:pointsBottomLeftA pointB:pointsBottomLeftB ctx:ctx];
    
    //右上角
    CGPoint pointsTopRightA[] = {
        CGPointMake(rect.origin.x + rect.size.width - 15, rect.origin.y + 0.7),
        CGPointMake(rect.origin.x + rect.size.width, rect.origin.y + 0.7 )
    };
    CGPoint pointsTopRightB[] = {
        CGPointMake(rect.origin.x + rect.size.width - 0.7, rect.origin.y),
        CGPointMake(rect.origin.x + rect.size.width - 0.7, rect.origin.y + 15.7 )
    };
    [self addLine:pointsTopRightA pointB:pointsTopRightB ctx:ctx];
    
    //右下角
    CGPoint pointsBottomRightA[] = {
        CGPointMake(rect.origin.x + rect.size.width - 0.7, rect.origin.y +rect.size.height - 15),
        CGPointMake(rect.origin.x - 0.7 + rect.size.width, rect.origin.y +rect.size.height)
    };
    CGPoint pointsBottomRightB[] = {
        CGPointMake(rect.origin.x + rect.size.width - 15, rect.origin.y + rect.size.height - 0.7),
        CGPointMake(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height - 0.7)
    };
    [self addLine:pointsBottomRightA pointB:pointsBottomRightB ctx:ctx];
    CGContextStrokePath(ctx);
}
 
- (void)addLine:(CGPoint[])pointA pointB:(CGPoint[])pointB ctx:(CGContextRef)ctx {
    CGContextAddLines(ctx, pointA, 2);
    CGContextAddLines(ctx, pointB, 2);
}
 
 
@end