ZXVideoPlayerTimeIndicatorView.m
2.82 KB
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
//
// ZXVideoPlayerTimeIndicatorView.m
// ZXVideoPlayer
//
// Created by Shawn on 16/4/21.
// Copyright © 2016年 Shawn. All rights reserved.
//
#import "ZXVideoPlayerTimeIndicatorView.h"
#import "ZXVideoPlayerControlView.h"
static const CGFloat kViewSpacing = 15.0;
static const CGFloat kTimeIndicatorAutoFadeOutTimeInterval = 1.0;
@interface ZXVideoPlayerTimeIndicatorView ()
@property (nonatomic, strong, readwrite) UIImageView *arrowImageView;
@property (nonatomic, strong, readwrite) UILabel *timeLabel;
@end
@implementation ZXVideoPlayerTimeIndicatorView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.hidden = YES;
self.layer.cornerRadius = 5;
self.layer.masksToBounds = YES;
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
[self createTimeIndicator];
}
return self;
}
- (void)setLabelText:(NSString *)labelText
{
// _labelText = [labelText copy];
self.hidden = NO;
self.timeLabel.text = labelText;
// 防止重叠显示
if (self.superview.accessibilityIdentifier) {
ZXVideoPlayerControlView *playerView = (ZXVideoPlayerControlView *)self.superview;
playerView.brightnessIndicatorView.hidden = YES;
playerView.volumeIndicatorView.hidden = YES;
} else {
self.superview.accessibilityIdentifier = @"";
}
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(animateHide) object:nil];
[self performSelector:@selector(animateHide) withObject:nil afterDelay:kTimeIndicatorAutoFadeOutTimeInterval];
}
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.playState == ZXTimeIndicatorPlayStateRewind) {
[self.arrowImageView setImage:[UIImage imageNamed:@"zx-video-player-rewind"]];
} else {
[self.arrowImageView setImage:[UIImage imageNamed:@"zx-video-player-fastForward"]];
}
}
- (void)createTimeIndicator
{
CGFloat margin = (kVideoTimeIndicatorViewSide - 24 - 12 - kViewSpacing) / 2;
_arrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake((kVideoTimeIndicatorViewSide - 44) / 2, margin, 44, 24)];
[self addSubview:_arrowImageView];
_timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, margin + 24 + kViewSpacing, kVideoTimeIndicatorViewSide, 12)];
_timeLabel.textColor = [UIColor whiteColor];
_timeLabel.backgroundColor = [UIColor clearColor];
_timeLabel.font = [UIFont systemFontOfSize:12];
_timeLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:_timeLabel];
}
- (void)animateHide
{
[UIView animateWithDuration:.3 animations:^{
self.alpha = 0;
} completion:^(BOOL finished) {
self.hidden = YES;
self.alpha = 1;
self.superview.accessibilityIdentifier = nil;
}];
}
@end