萤石云 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//
//  HIKLoadView.m
//  VideoGo
//
//  Created by zhil.shi on 15/3/9.
//  Copyright (c) 2015年 HIKVison. All rights reserved.
//
 
#import "HIKLoadView.h"
#import "HIKLoadViewItem.h"
#import "HIKLoadViewItem+configPath.h"
static float SQUARE_FIT_LEN = 14.0;
 
@interface HIKLoadView ()
 
@property (nonatomic,strong) CALayer         *animationLayer;
@property (nonatomic,strong) HIKLoadViewItem *blueCircle;
@property (nonatomic,strong) HIKLoadViewItem *greenCircle;
@property (nonatomic,strong) HIKLoadViewItem *redCircle;
@property (nonatomic,strong) HIKLoadViewItem *yellowCircle;
@property (nonatomic,strong) UILabel         *percentLable;
@end
 
@implementation HIKLoadView
#pragma mark - init 初始化
- (instancetype)initWithHIKLoadViewStyle:(HIKLoadViewStyle)style
{
    self = [super init];
    if(!self)return nil;
    
    switch (style) {
        case HIKLoadViewStyleSqureClockWise:
        {
            [self setFrame:CGRectMake(0.0, 0.0, SQUARE_FIT_LEN, SQUARE_FIT_LEN)];
            [self p_setUp];
            [self p_setUpCircleLayersCenter];
        }
            break;
        case HIKLoadViewStyleSqureCornersClockWise:
        {
            [self setFrame:CGRectMake(0.0, 0.0, SQUARE_FIT_LEN, SQUARE_FIT_LEN)];
            [self p_setUp];
            [self p_setUpCorcleLayersSquareCorners];
        }
            break;
            
        default:
            break;
    }
    
    return self;
}
 
- (instancetype)initWithHIKLoadViewStyle:(HIKLoadViewStyle)style frame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(!self)return nil;
    
    switch (style) {
        case HIKLoadViewStyleSqureClockWise:
        {
            [self p_setUp];
            [self p_setUpCircleLayersCenter];
        }
            break;
        case HIKLoadViewStyleSqureCornersClockWise:
        {
            [self p_setUp];
            [self p_setUpCorcleLayersSquareCorners];
        }
            break;
            
        default:
            break;
    }
    
    return self;
}
 
#pragma mark -setUp 私有方法相关设置
- (void)p_setUp
{
    [self setBackgroundColor:[UIColor clearColor]];
    [self p_setUpCircleLayers];
    
}
 
/**
 *  初始化需要的layer
 */
- (void)p_setUpCircleLayers
{
    if(!self.animationLayer)
    {
        self.animationLayer = self.layer;
    }
    
    if(!self.yellowCircle)
    {
        UIImage* yellowImage = [UIImage imageNamed:@"logo_loading_4"];
        self.yellowCircle    = [HIKLoadViewItem initWithImage:yellowImage];
        [self.animationLayer addSublayer:self.yellowCircle.colorCirculeLayer];
    }
    
    if(!self.redCircle)
    {
        UIImage* redImage = [UIImage imageNamed:@"logo_loading_3"];
        self.redCircle    = [HIKLoadViewItem initWithImage:redImage];
        [self.animationLayer addSublayer:self.redCircle.colorCirculeLayer];
    }
    
    if(!self.greenCircle)
    {
        UIImage* greenImage = [UIImage imageNamed:@"logo_loading_2"];
        self.greenCircle    = [HIKLoadViewItem initWithImage:greenImage];
        [self.animationLayer addSublayer:self.greenCircle.colorCirculeLayer];
    }
    
    if(!self.blueCircle)
    {
        UIImage* blueImage = [UIImage imageNamed:@"logo_loading_1"];
        self.blueCircle    = [HIKLoadViewItem initWithImage:blueImage];
        [self.animationLayer addSublayer:self.blueCircle.colorCirculeLayer];
    }
    
}
/**
 *  初始化百分比显示lable
 */
- (void)p_initPercentLable
{
    if(self.percentLable)return;
    
    self.percentLable = [[UILabel alloc]init];
    [self.percentLable setBackgroundColor:[UIColor clearColor]];
    [self.percentLable setTextAlignment:NSTextAlignmentCenter];
    
}
/**
 *  移除layers傻姑娘的所有动画
 */
- (void)p_removeAllAniamations
{
    [self.blueCircle.colorCirculeLayer removeAllAnimations];
    [self.greenCircle.colorCirculeLayer removeAllAnimations];
    [self.redCircle.colorCirculeLayer removeAllAnimations];
    [self.yellowCircle.colorCirculeLayer removeAllAnimations];
}
/**
 *  设置正方形顺时针旋转动画
 */
- (void)p_setUpAnimations
{
    [self.blueCircle configKeyFrameAnimationForColorLayerWithStartLoadingStyle:HIKLoadViewStartFromLeftTop];
    [self.greenCircle configKeyFrameAnimationForColorLayerWithStartLoadingStyle:HIKLoadViewStartFromRightTop];
    [self.redCircle configKeyFrameAnimationForColorLayerWithStartLoadingStyle:HIKLoadViewStartFromLeftBottom];
    [self.yellowCircle configKeyFrameAnimationForColorLayerWithStartLoadingStyle:HIKLoadViewStartFromRightBottom];
}
 
- (void)p_setUpCircleLayersCenter
{
    CGPoint centerPoint = CGPointMake(SQUARE_FIT_LEN/2.0, SQUARE_FIT_LEN/2.0);
    [self.yellowCircle setPosition:centerPoint];
    [self.redCircle setPosition:centerPoint];
    [self.greenCircle setPosition:centerPoint];
    [self.blueCircle setPosition:centerPoint];
}
 
- (void)p_stayCircleLayersPresentationLayerPosition
{
    [self.yellowCircle stayOnPresentationLayerPosition];
    [self.redCircle stayOnPresentationLayerPosition];
    [self.greenCircle stayOnPresentationLayerPosition];
    [self.blueCircle stayOnPresentationLayerPosition];
    [self.greenCircle.colorCirculeLayer setOpacity:0];
    [self.redCircle.colorCirculeLayer setOpacity:0];
    [self.blueCircle.colorCirculeLayer setOpacity:0];
    [self.yellowCircle.colorCirculeLayer setOpacity:0];
 
}
 
/**
 *  设置起始位置为正方形四角
 */
- (void)p_setUpCorcleLayersSquareCorners
{
    CGPoint leftTop     = CGPointMake(0.0, 0.0);
    CGPoint rightTop    = CGPointMake(SQUARE_FIT_LEN, 0.0);
    CGPoint rightBottom = CGPointMake(SQUARE_FIT_LEN, SQUARE_FIT_LEN);
    CGPoint leftBottom  = CGPointMake(0.0, SQUARE_FIT_LEN);
    [self.blueCircle setPosition:leftTop];
    [self.greenCircle setPosition:rightTop];
    [self.yellowCircle setPosition:rightBottom];
    [self.redCircle setPosition:leftBottom];
}
 
 
#pragma mark -animations
- (void)updateReadytoClockwiseAnimationWithPercent:(float)percent
{
    if(percent < 0.0 || percent > 1.0)
    {
        return;
    }
    
    percent = ((int)(percent * 10))/10.0;
 
    
    CGPoint center            = CGPointMake(CGRectGetMidX(self.frame) -CGRectGetMinX(self.frame), CGRectGetMidY(self.frame)-CGRectGetMinY(self.frame));
    CGPoint blueTargetPoint   = CGPointMake(center.x  * (1-percent), center.y * (1-percent));
    CGPoint greenTargetPoint  = CGPointMake(center.x * (1+percent), center.y * (1-percent));
    CGPoint yellowTargetPoint = CGPointMake(center.x * (1+percent), center.y * (1+percent));
    CGPoint redTargetPoint    = CGPointMake(center.x * (1-percent), center.y * (1+percent));
    
    [self.blueCircle setPosition:blueTargetPoint];//blue最上层,透明度不设置
    [self.greenCircle setPosition:greenTargetPoint];
    [self.redCircle setPosition:redTargetPoint];
    [self.yellowCircle setPosition:yellowTargetPoint];
    [self.blueCircle.colorCirculeLayer setOpacity:1.0];
    [self.redCircle.colorCirculeLayer setOpacity:percent];
    [self.greenCircle.colorCirculeLayer setOpacity:percent];
    [self.yellowCircle.colorCirculeLayer setOpacity:percent];
 
    
}
 
- (void)startSquareClcokwiseAnimation
{
    [self p_removeAllAniamations];
    [self p_setUpCircleLayersCenter];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self p_setUpAnimations];
    });
 
}
 
- (void)stopSquareClockwiseAnimation
{
    [self p_stayCircleLayersPresentationLayerPosition];
    [self p_removeAllAniamations];
}
 
@end