萤石云 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
//
//  HIKLoadPercentView.m
//  VideoGo
//
//  Created by zhil.shi on 15/3/9.
//  Copyright (c) 2015年 HIKVison. All rights reserved.
//
 
#import "HIKLoadPercentView.h"
#import "HIKLoadView.h"
@interface HIKLoadPercentView()
 
@property (strong, nonatomic,readwrite) NSString    *percentStr;
@property (nonatomic,strong   ) HIKLoadView *loadingView;
@property (nonatomic,strong   ) UILabel     *percentLable;
@end
 
@implementation HIKLoadPercentView
{
    unsigned int         _nLoadProcent;     // 加载百分比
    NSTimer             *_tLoadTimer;       // 加载定时器
    int                  _nLoadSeconds;     // 加载等待时间
}
#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame percentStr:(NSString *)percentStr
{
    self = [super initWithFrame:frame];
    if(self)
    {
        [self p_setUp];
        [self setShowContent:percentStr];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame percentStr:(NSString *)percentStr percentColor:(UIColor *)color
{
    self = [self initWithFrame:frame percentStr:percentStr];
    [self.percentLable setTextColor:color];
    return self;
}
- (NSString *)percentStr
{
   return  self.percentLable.text;
}
 
#pragma mark - 私有方法 相关设置
- (void)p_setUp
{
    [self setBackgroundColor:[UIColor clearColor]];
    [self setClipsToBounds:NO];
    
    //loadView
    self.loadingView  = [[HIKLoadView alloc]initWithHIKLoadViewStyle:HIKLoadViewStyleSqureCornersClockWise];
    float center_y = MIN(CGRectGetMidY(self.loadingView.frame), CGRectGetMidY(self.frame));
    [self.loadingView setCenter:CGPointMake(self.frame.size.width/2.0,center_y)];
    
    __weak typeof (self.loadingView) weakLodingView = self.loadingView;
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakLodingView startSquareClcokwiseAnimation];
    });
    [self addSubview:self.loadingView];
    
    //percent
    self.percentLable = [[UILabel alloc]init];
    [self.percentLable setBackgroundColor:[UIColor clearColor]];
    [self.percentLable setTextAlignment:NSTextAlignmentCenter];
    [self.percentLable setFont:[UIFont systemFontOfSize:14.0]];
    [self.percentLable setFrame:CGRectMake(0.0, CGRectGetMaxY(self.loadingView.frame)+5,CGRectGetWidth(self.frame), 30)];
    [self.percentLable setTextColor:[UIColor whiteColor]];
    [self addSubview:self.percentLable];
    
}
 
#pragma mark -actions
 
- (void)setShowContent:(NSString *)content
{
    if(content)
    self.percentLable.text = content;
 
}
 
 
- (void)showPercentAnimation
{
    self.percentLable.text = @"0%";
    self.hidden = NO;
    
    dispatch_async(dispatch_get_main_queue(), ^
                   {
                       [self startAdmView];
                   });
}
 
- (void)startAdmView
{
    _nLoadProcent = 0;
    // 开启定时器,用于启动百分比计算
    if ([_tLoadTimer isValid])
    {
        [_tLoadTimer invalidate];
    }
    _tLoadTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
                                                   target:self
                                                 selector:@selector(updateWaitTime:)
                                                 userInfo:nil
                                                  repeats:YES];
    
}
 
- (void)updateWaitTime:(NSTimer *)timer
{
    [self setWaitTime];
    
    _nLoadSeconds++;
    
}
 
/** @fn    setWaitTime
 *  @brief  等待百分比计数
 *  @param  无
 *  @return 无
 */
- (void)setWaitTime
{
    int x = arc4random() % 15;
    if(_nLoadProcent < 85)
    {
        _nLoadProcent = _nLoadProcent + x;
    }
    
    NSString * strTips = [NSString stringWithFormat:@"%d%%", _nLoadProcent];
    self.percentLable.text = strTips;
}
 
 
- (void)hideRemovePercentAnimation
{
    self.hidden = YES;
    _nLoadProcent = 0;
    self.percentLable.text = @"0%";
    
    if ([_tLoadTimer isValid])
    {
        [_tLoadTimer invalidate];
        _tLoadTimer = nil;
    }
    
 
}
 
@end