PlayFunctionView.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // PlayFunctionView.m
  3. // XMEye
  4. //
  5. // Created by XM on 2016/6/26.
  6. // Copyright © 2016年 Megatron. All rights reserved.
  7. //
  8. #import "PlayFunctionView.h"
  9. #import "Header.h"
  10. @implementation PlayFunctionView
  11. - (UIImageView *)imageV{
  12. if (!_imageV) {
  13. _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 60)];
  14. _imageV.backgroundColor = [UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1];
  15. }
  16. return _imageV;
  17. }
  18. - (UILabel *)timeLab{
  19. if (!_timeLab) {
  20. _timeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
  21. _timeLab.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
  22. _timeLab.textAlignment = NSTextAlignmentCenter;
  23. _timeLab.font = [UIFont systemFontOfSize:19];
  24. _timeLab.textColor = [UIColor whiteColor];
  25. }
  26. return _timeLab;
  27. }
  28. - (instancetype)initWithFrame:(CGRect)frame{
  29. self = [super initWithFrame:frame];
  30. if (self) {
  31. self.functionArray = [[NSMutableArray alloc] initWithCapacity:0];
  32. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recodeTime:) name:@"recodeTime" object:nil];
  33. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearRecodeTime) name:@"recodeEnd" object:nil];
  34. }
  35. return self;
  36. }
  37. #pragma mark - 录像计时器
  38. - (void)recodeTime:(NSNotification *)notification{
  39. for (UIButton * btn in self.functionArray) {
  40. if ([btn isKindOfClass:[UIButton class]]) {
  41. if (btn.tag == 4) {
  42. [btn addSubview:self.timeLab];
  43. self.timeLab.text = notification.object;
  44. }
  45. }
  46. }
  47. }
  48. - (void)clearRecodeTime{
  49. self.timeLab.text = @"";
  50. }
  51. - (void)setPlayMode:(PLAY_MODE)playMode{
  52. for (UIButton *btn in self.subviews){
  53. [btn removeFromSuperview];
  54. }
  55. [self.functionArray removeAllObjects];
  56. [self configSubViewWithPlayMode:playMode];
  57. }
  58. - (void)configSubViewWithPlayMode:(PLAY_MODE)playMode{
  59. [self addSubview:self.imageV];
  60. self.imageV.alpha = 1.0;
  61. if (playMode == PLAYBACK_MODE) {
  62. [self.functionArray addObject:[self getButtonBykey:@"暂停"]];
  63. [self.functionArray addObject:[self getButtonBykey:@"音频"]];
  64. [self.functionArray addObject:[self getButtonBykey:@"速度"]];
  65. [self.functionArray addObject:[self getButtonBykey:@"抓图"]];
  66. [self.functionArray addObject:[self getButtonBykey:@"录像"]];
  67. }
  68. else{
  69. [self.functionArray addObject:[self getButtonBykey:@"暂停"]];
  70. [self.functionArray addObject:[self getButtonBykey:@"音频"]];
  71. [self.functionArray addObject:[self getButtonBykey:@"对讲"]];
  72. [self.functionArray addObject:[self getButtonBykey:@"抓图"]];
  73. [self.functionArray addObject:[self getButtonBykey:@"录像"]];
  74. }
  75. //数据添加完毕之后,进行刷新
  76. [self refreshFrame];
  77. }
  78. - (void)refreshFrame{
  79. for (int i = 0; i < self.functionArray.count; i++) {
  80. CGFloat height = self.frame.size.height;
  81. UIButton *btn = [self.functionArray objectAtIndex:i];
  82. btn.frame = CGRectMake(0, 0, self.frame.size.height, height - 10);
  83. if (height <= 40) { //防止按钮过小
  84. btn.frame = CGRectMake(0, 0, height, height);
  85. }
  86. btn.center = CGPointMake((i+1) * self.frame.size.width/(self.functionArray.count + 1),self.frame.size.height/2);
  87. [btn addTarget:self action:@selector(functionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  88. }
  89. }
  90. #pragma mark - 点击按钮的代理
  91. - (void)functionBtnClick:(UIButton *)sender{
  92. if (self.Devicedelegate && [self.Devicedelegate respondsToSelector:@selector(basePlayFunctionViewBtnClickWithBtn:)]) {
  93. [self.Devicedelegate basePlayFunctionViewBtnClickWithBtn:(int)sender.tag];
  94. }
  95. }
  96. - (UIButton *)getButtonBykey:(NSString *)key{
  97. if (_btnDic == nil) {
  98. NSString *playToolImagePath = [[NSBundle mainBundle] pathForResource:@"PlayToolImage.plist" ofType:nil];
  99. NSDictionary *imageDic = [[NSDictionary alloc] initWithContentsOfFile:playToolImagePath];
  100. if (imageDic == nil) {
  101. return [UIButton buttonWithType:UIButtonTypeCustom];
  102. }
  103. _btnDic = [[imageDic objectForKey:@"ButtonObject"] mutableCopy];
  104. if (_btnDic == nil) {
  105. return [UIButton buttonWithType:UIButtonTypeCustom];
  106. }
  107. }
  108. NSDictionary *dic = [_btnDic objectForKey:key];
  109. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
  110. [btn setBackgroundImage:[UIImage imageNamed:[dic objectForKey:@"NormalState"]] forState:UIControlStateNormal];
  111. [btn setBackgroundImage:[UIImage imageNamed:[dic objectForKey:@"SelectedState"]] forState:UIControlStateSelected];
  112. [btn setTitle:[dic objectForKey:@"title"] forState:UIControlStateNormal];
  113. [btn setTitle:[dic objectForKey:@"selectTitle"] forState:UIControlStateSelected];
  114. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  115. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  116. btn.tag = [[dic objectForKey:@"EventTypeNumber"] integerValue];
  117. [self addSubview:btn];
  118. return btn;
  119. }
  120. - (void)refreshFunctionView:(int)tag result:(BOOL)result {
  121. for (UIButton *btn in self.functionArray) {
  122. if ([btn isKindOfClass:[UIButton class]]) {
  123. if (btn.tag == tag) {
  124. btn.selected = result;
  125. }
  126. }
  127. }
  128. }
  129. #pragma mark 显示速度控制悬浮框,几秒后隐藏
  130. - (BOOL)showPlayFunctionView{
  131. BOOL result = NO;
  132. result = self.hidden;
  133. [self show];
  134. return result;
  135. }
  136. - (void)show{
  137. //设置自己的hidden属性为NO,并且开启一个延时方法,5秒后隐藏
  138. self.hidden = NO;
  139. if (self.Devicedelegate && [self.Devicedelegate respondsToSelector:@selector(dismissPTZControlView)]) {
  140. [self.Devicedelegate showStreamBtn];
  141. }
  142. if (!self.screenVertical) {
  143. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(dismis) object:nil];
  144. [self performSelector:@selector(dismis) withObject:nil afterDelay:5.0];
  145. }else{
  146. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(dismis) object:nil];
  147. }
  148. }
  149. - (void)dismis{
  150. self.hidden = YES;
  151. if (self.Devicedelegate && [self.Devicedelegate respondsToSelector:@selector(dismissPTZControlView)]) {
  152. [self.Devicedelegate dismissPTZControlView];
  153. }
  154. }
  155. - (void)dealloc {
  156. [[NSNotificationCenter defaultCenter] removeObserver:self];
  157. }
  158. @end