webRtcPlayerViewController+AdjustPlayerViewFrame.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // webRtcPlayerViewController+AdjustPlayerViewFrame.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/9/5.
  6. //
  7. #import "webRtcPlayerViewController+AdjustPlayerViewFrame.h"
  8. @implementation webRtcPlayerViewController (AdjustPlayerViewFrame)
  9. - (void)setPoMas_makeWithImageRate:(CGFloat)w_h_rate{
  10. /*播放视图*/
  11. // touchCommondView.isLan = NO;
  12. lastVideoWHRate = w_h_rate;
  13. BOOL fullScreenShow = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  14. [self.mediaStream mas_remakeConstraints:^(MASConstraintMaker *make) {
  15. CGFloat scr_W = SCREEN_W;
  16. CGFloat scr_H = SCREEN_H;
  17. if (SCREEN_W > SCREEN_H){
  18. scr_W = SCREEN_H;
  19. scr_H = SCREEN_W;
  20. }
  21. if(fullScreenShow){//全屏
  22. make.left.mas_equalTo(0.f);
  23. make.right.mas_equalTo(0.f);
  24. make.bottom.mas_equalTo(0.f);
  25. make.top.mas_equalTo(0.f);
  26. }
  27. else{//非全屏
  28. if ((scr_H - scr_W/w_h_rate - 40.f) < 0){//空余高度不满 40 (宽不能满屏)
  29. make.height.mas_equalTo(scr_H - 40.f);
  30. make.width.mas_equalTo((scr_H - 40.f)*w_h_rate);
  31. make.centerX.equalTo(self.view.mas_centerX);
  32. make.top.mas_equalTo(0);
  33. }
  34. else if ((scr_H - scr_W/w_h_rate - 40.f*2) < 0){//空余高度不满 80 (Y不能居中)
  35. make.height.mas_equalTo(scr_H);
  36. make.width.mas_equalTo((scr_H)*w_h_rate);
  37. make.centerX.equalTo(self.view.mas_centerX);
  38. make.bottom.mas_equalTo(-40);
  39. }
  40. else{// 宽满屏 Y居中
  41. make.left.mas_equalTo(0.f);
  42. make.right.mas_equalTo(0.f);
  43. make.height.mas_equalTo(scr_W/w_h_rate);
  44. //make.top.mas_equalTo((scr_H - scr_W/w_h_rate - 40.f)/2.f);
  45. make.centerY.equalTo(self.view.mas_centerY);
  46. }
  47. }
  48. }];
  49. //[self.mediaStream setVideoContentMode:UIViewContentModeScaleAspectFit];
  50. [self.bottomContrView mas_remakeConstraints:^(MASConstraintMaker *make) {
  51. make.height.mas_equalTo(40.f);
  52. make.right.mas_equalTo(0.f);
  53. if(fullScreenShow){
  54. make.bottom.mas_equalTo(0);
  55. }
  56. else{
  57. make.top.equalTo(self.mediaStream.mas_bottom);
  58. }
  59. make.left.mas_equalTo(0.f);
  60. }];
  61. [self.bottomContrView updateFrameFunByIsLan:NO];
  62. }
  63. /**
  64. * @brief 设置横屏模式UI布局
  65. *
  66. * @param w_h_rate 宽高比
  67. */
  68. - (void)setLanMas_makeWithImageRate:(CGFloat)w_h_rate{
  69. lastVideoWHRate = w_h_rate;
  70. BOOL fullScreenShow = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  71. CGFloat h_forPhoneBottomView = 40.0;
  72. CGFloat h_forPhoneTop = 0;
  73. if (IPHONE_X){
  74. h_forPhoneTop = 44.f;
  75. }
  76. // CGFloat des_W = SCREEN_W<SCREEN_H?SCREEN_W:SCREEN_H;/*实际较小的数字*/
  77. // CGFloat des_H = (SCREEN_W>SCREEN_H?SCREEN_W:SCREEN_H) - h_forPhoneTop;/*实际较大的数字*/
  78. // [self.mediaStream mas_remakeConstraints:^(MASConstraintMaker *make) {
  79. // make.bottom.mas_equalTo(0.f);
  80. // make.width.mas_equalTo(des_W*w_h_rate);
  81. // make.left.mas_equalTo(h_forPhoneTop + (des_H - h_forPhoneBottomView - des_W*w_h_rate)/2.f);
  82. // make.top.mas_equalTo(0);
  83. // }];
  84. [self.mediaStream mas_remakeConstraints:^(MASConstraintMaker *make) {
  85. CGFloat scr_W = SCREEN_W;
  86. CGFloat scr_H = SCREEN_H;
  87. if (SCREEN_W < SCREEN_H){
  88. scr_W = SCREEN_H;
  89. scr_H = SCREEN_W;
  90. }
  91. if(fullScreenShow){//全屏
  92. make.left.mas_equalTo(0.f);
  93. make.right.mas_equalTo(0.f);
  94. make.bottom.mas_equalTo(0.f);
  95. make.top.mas_equalTo(0.f);
  96. }
  97. else{//非全屏
  98. if ((scr_W - scr_H*w_h_rate - 40.f) < 0){//空余宽度不满 40 (高不能满屏)
  99. make.height.mas_equalTo((scr_W - 40.f)/w_h_rate);
  100. make.width.mas_equalTo(scr_W - 40.f);
  101. make.centerX.equalTo(self.view.mas_centerX);
  102. make.left.mas_equalTo(0);
  103. }
  104. else if ((scr_W - scr_H*w_h_rate - 40.f*2) < 0){//空余宽度不满 80 (X不能居中)
  105. make.height.mas_equalTo(scr_H);
  106. make.width.mas_equalTo((scr_H)*w_h_rate);
  107. make.centerY.equalTo(self.view.mas_centerX);
  108. make.right.mas_equalTo(-40);
  109. }
  110. else{// 高满屏 X居中
  111. make.height.mas_equalTo(scr_H);
  112. make.top.mas_equalTo(0.f);
  113. make.width.mas_equalTo(scr_H*w_h_rate);
  114. make.centerX.equalTo(self.view.mas_centerX);
  115. }
  116. }
  117. }];
  118. [self.bottomContrView mas_remakeConstraints:^(MASConstraintMaker *make) {
  119. make.width.mas_equalTo(h_forPhoneBottomView);
  120. if(fullScreenShow){
  121. make.right.mas_equalTo(0);
  122. }
  123. else{
  124. make.left.equalTo(self.mediaStream.mas_right);
  125. }
  126. make.top.mas_equalTo(0);
  127. make.bottom.mas_equalTo(0);
  128. }];
  129. [self.bottomContrView updateFrameFunByIsLan:YES];
  130. }
  131. @end