PTZView.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // PTZView.m
  3. // XMEye
  4. //
  5. // Created by Levi on 2017/6/23.
  6. // Copyright © 2017年 Megatron. All rights reserved.
  7. //
  8. #import "PTZView.h"
  9. #import "FunSDK/netsdk.h"
  10. #import "Header.h"
  11. @implementation PTZView
  12. -(UIImageView *)PTZControlIV{
  13. if (!_PTZControlIV) {
  14. _PTZControlIV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
  15. _PTZControlIV.center = CGPointMake(self.frame.size.width * 0.5 - 60 - 30, self.frame.size.height * 0.5);
  16. _PTZControlIV.image = [UIImage imageNamed:@"btn_control_normal.png"];
  17. _PTZControlIV.userInteractionEnabled = YES;
  18. }
  19. return _PTZControlIV;
  20. }
  21. -(UIButton *)PTZUpBtn{
  22. if (!_PTZUpBtn) {
  23. _PTZUpBtn = [[UIButton alloc] initWithFrame:CGRectMake(40, 0, 40, 40)];
  24. _PTZUpBtn.backgroundColor = [UIColor clearColor];
  25. _PTZUpBtn.tag = TILT_UP;
  26. [_PTZUpBtn addTarget:self action:@selector(TouchDownAction:) forControlEvents:UIControlEventTouchDown];
  27. [_PTZUpBtn addTarget:self action:@selector(TouchUpInsideAction:) forControlEvents:UIControlEventTouchCancel];
  28. [_PTZUpBtn addTarget:self action:@selector(TouchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside];
  29. }
  30. return _PTZUpBtn;
  31. }
  32. -(UIButton *)PTZDownBtn{
  33. if (!_PTZDownBtn) {
  34. _PTZDownBtn = [[UIButton alloc] initWithFrame:CGRectMake(40, 80, 40, 40)];
  35. _PTZDownBtn.backgroundColor = [UIColor clearColor];
  36. _PTZDownBtn.tag = TILT_DOWN;
  37. [_PTZDownBtn addTarget:self action:@selector(TouchDownAction:) forControlEvents:UIControlEventTouchDown];
  38. [_PTZDownBtn addTarget:self action:@selector(TouchUpInsideAction:) forControlEvents:UIControlEventTouchCancel];
  39. [_PTZDownBtn addTarget:self action:@selector(TouchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside];
  40. }
  41. return _PTZDownBtn;
  42. }
  43. -(UIButton *)PTZLeftBtn{
  44. if (!_PTZLeftBtn) {
  45. _PTZLeftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 40, 40, 40)];
  46. _PTZLeftBtn.backgroundColor = [UIColor clearColor];
  47. _PTZLeftBtn.tag = PAN_LEFT;
  48. [_PTZLeftBtn addTarget:self action:@selector(TouchDownAction:) forControlEvents:UIControlEventTouchDown];
  49. [_PTZLeftBtn addTarget:self action:@selector(TouchUpInsideAction:) forControlEvents:UIControlEventTouchCancel];
  50. [_PTZLeftBtn addTarget:self action:@selector(TouchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside];
  51. }
  52. return _PTZLeftBtn;
  53. }
  54. -(UIButton *)PTZRightBtn{
  55. if (!_PTZRightBtn) {
  56. _PTZRightBtn = [[UIButton alloc] initWithFrame:CGRectMake(80, 40, 40, 40)];
  57. _PTZRightBtn.backgroundColor = [UIColor clearColor];
  58. _PTZRightBtn.tag = PAN_RIGHT;
  59. [_PTZRightBtn addTarget:self action:@selector(TouchDownAction:) forControlEvents:UIControlEventTouchDown];
  60. [_PTZRightBtn addTarget:self action:@selector(TouchUpInsideAction:) forControlEvents:UIControlEventTouchCancel];
  61. [_PTZRightBtn addTarget:self action:@selector(TouchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside];
  62. }
  63. return _PTZRightBtn;
  64. }
  65. -(UIButton *)closeBtn{
  66. if (!_closeBtn) {
  67. _closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width - 50,10 , 40, 40)];
  68. [_closeBtn setBackgroundImage:[UIImage imageNamed:@"icon_close"] forState:UIControlStateNormal];
  69. [_closeBtn addTarget:self action:@selector(removeTheView:) forControlEvents:UIControlEventTouchUpInside];
  70. }
  71. return _closeBtn;
  72. }
  73. -(instancetype)initWithFrame:(CGRect)frame{
  74. self = [super initWithFrame:frame];
  75. if (self) {
  76. self.backgroundColor = [UIColor whiteColor];
  77. [self configSubView];
  78. }
  79. return self;
  80. }
  81. -(void)configSubView{
  82. [self addSubview:self.closeBtn];
  83. [self addSubview:self.PTZControlIV];
  84. [self.PTZControlIV addSubview:self.PTZUpBtn];
  85. [self.PTZControlIV addSubview:self.PTZDownBtn];
  86. [self.PTZControlIV addSubview:self.PTZLeftBtn];
  87. [self.PTZControlIV addSubview:self.PTZRightBtn];
  88. for (int i = 0; i<6; i++) {
  89. [self createBtnWithTag:i];
  90. }
  91. [self createLab];
  92. }
  93. -(void)createBtnWithTag:(int)tag{
  94. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
  95. if (tag <= 2) {
  96. btn.center = CGPointMake(self.frame.size.width * 0.5 + 15 +40*tag,self.frame.size.height * 0.5 - 30);
  97. [btn setBackgroundImage:[UIImage imageNamed:@"btn_plus_normal.png"] forState:UIControlStateNormal];
  98. [btn setBackgroundImage:[UIImage imageNamed:@"btn_plus_highlighted.png"] forState:UIControlStateHighlighted];
  99. }else{
  100. btn.center = CGPointMake(self.frame.size.width * 0.5 + 15 +40*(tag -3),self.frame.size.height * 0.5 + 30);
  101. [btn setBackgroundImage:[UIImage imageNamed:@"btn_minus_normal.png"] forState:UIControlStateNormal];
  102. [btn setBackgroundImage:[UIImage imageNamed:@"btn_minus_highlighted.png"] forState:UIControlStateHighlighted];
  103. }
  104. if (tag == 0) {
  105. btn.tag = ZOOM_IN_1;
  106. }else if (tag == 1){
  107. btn.tag = FOCUS_NEAR;
  108. }else if (tag == 2){
  109. btn.tag = IRIS_OPEN;
  110. }else if (tag == 3){
  111. btn.tag = ZOOM_OUT_1;
  112. }else if (tag == 4){
  113. btn.tag = FOCUS_FAR;
  114. }else{
  115. btn.tag = IRIS_CLOSE;
  116. }
  117. [btn addTarget:self action:@selector(changeSpeed:) forControlEvents:UIControlEventTouchDown];
  118. [btn addTarget:self action:@selector(stopchangeSubSpeed:) forControlEvents:UIControlEventTouchCancel];
  119. [btn addTarget:self action:@selector(stopchangeSubSpeed:) forControlEvents:UIControlEventTouchUpInside];
  120. [self addSubview:btn];
  121. }
  122. -(void)createLab{
  123. UILabel *labZoom = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 25)];
  124. labZoom.center = CGPointMake(self.frame.size.width * 0.5 + 15, self.frame.size.height * 0.5);
  125. labZoom.text = TS("Zoom");
  126. labZoom.textColor = NormalFontColor;
  127. labZoom.font = [UIFont systemFontOfSize:14];
  128. labZoom.textAlignment = NSTextAlignmentCenter;
  129. labZoom.backgroundColor = [UIColor clearColor];
  130. UILabel *labFocus = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 25)];
  131. labFocus.center = CGPointMake(self.frame.size.width * 0.5 + 55, self.frame.size.height * 0.5);
  132. labFocus.text = TS("Focus");
  133. labFocus.textColor = NormalFontColor;
  134. labFocus.font = [UIFont systemFontOfSize:14];
  135. labFocus.textAlignment = NSTextAlignmentCenter;
  136. labFocus.backgroundColor = [UIColor clearColor];
  137. UILabel *labIris = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 25)];
  138. labIris.center = CGPointMake(self.frame.size.width * 0.5 + 95, self.frame.size.height * 0.5);
  139. labIris.text = TS("Iris");
  140. labIris.textColor = NormalFontColor;
  141. labIris.font = [UIFont systemFontOfSize:14];
  142. labIris.textAlignment = NSTextAlignmentCenter;
  143. labIris.backgroundColor = [UIColor clearColor];
  144. [self addSubview:labZoom];
  145. [self addSubview:labFocus];
  146. [self addSubview:labIris];
  147. }
  148. #pragma mark - 点击云台控制的按钮
  149. -(void)TouchDownAction:(UIButton *)sender{
  150. switch (sender.tag) {
  151. case 0:
  152. _PTZControlIV.image = [UIImage imageNamed:@"btn_control_up.png"];
  153. break;
  154. case 1:
  155. _PTZControlIV.image = [UIImage imageNamed:@"btn_control_down.png"];
  156. break;
  157. case 2:
  158. _PTZControlIV.image = [UIImage imageNamed:@"btn_control_left.png"];
  159. break;
  160. case 3:
  161. _PTZControlIV.image = [UIImage imageNamed:@"btn_control_right.png"];
  162. break;
  163. default:
  164. break;
  165. }
  166. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  167. _PTZControlIV.image = [UIImage imageNamed:@"btn_control_normal.png"];
  168. });
  169. if (self.PTZdelegate && [self.PTZdelegate respondsToSelector:@selector(controlPTZBtnTouchDownAction:)]) {
  170. [self.PTZdelegate controlPTZBtnTouchDownAction:(int)sender.tag];
  171. }
  172. }
  173. #pragma mark - 抬起云台控制的按钮
  174. -(void)TouchUpInsideAction:(UIButton *)sender{
  175. if (self.PTZdelegate && [self.PTZdelegate respondsToSelector:@selector(controlPTZBtnTouchUpInsideAction:)]) {
  176. [self.PTZdelegate controlPTZBtnTouchUpInsideAction:(int)sender.tag];
  177. }
  178. }
  179. #pragma mark - 点击控制的按钮(变倍,变焦,光圈)
  180. -(void)changeSpeed:(UIButton *)sender{
  181. if (self.speedDelegate && [self.speedDelegate respondsToSelector:@selector(controladdSpeedTouchDownAction:)]) {
  182. [self.speedDelegate controladdSpeedTouchDownAction:(int)sender.tag];
  183. }
  184. }
  185. #pragma mark - 抬起控制的按钮(变倍,变焦,光圈)
  186. -(void)stopchangeSubSpeed:(UIButton *)sender{
  187. if (self.speedDelegate && [self.speedDelegate respondsToSelector:@selector(controladdSpeedTouchUpInsideAction:)]) {
  188. [self.speedDelegate controladdSpeedTouchUpInsideAction:(int)sender.tag];
  189. }
  190. }
  191. -(void)removeTheView:(UIButton *)sender{
  192. [self removeFromSuperview];
  193. }
  194. @end