MORulesWebBaseView.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // MORulesWebBaseView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2025/9/11.
  6. //
  7. #import "MORulesWebBaseView.h"
  8. #import "MOWebBaseView.h"
  9. @interface MORulesWebBaseView ()
  10. @property (nonatomic, strong) UIView *bgView;
  11. @property (nonatomic, strong) BigBtn *backBtn;
  12. @property (nonatomic, strong) UILabel *titleLab;
  13. @property (nonatomic, strong) MOWebBaseView *webView;
  14. @property (nonatomic, strong) UIButton *closeBtn;
  15. @end
  16. @implementation MORulesWebBaseView
  17. - (instancetype)init {
  18. if (self = [super init] ) {
  19. [self setupUI];
  20. }
  21. return self;
  22. }
  23. - (instancetype)initWithFrame:(CGRect)frame{
  24. self = [super initWithFrame:frame];
  25. if (self){
  26. [self setupUI];
  27. }
  28. return self;
  29. }
  30. - (void)setupUI{
  31. [self addSubview:self.bgView];
  32. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.bottom.left.right.equalTo(self);
  34. make.height.equalTo(@(kScaleWidth(522.0)));
  35. }];
  36. [self.bgView addSubview:self.titleLab];
  37. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.equalTo(self.bgView).offset(10.0);
  39. make.left.equalTo(self.bgView).offset(55.0);
  40. make.right.equalTo(self.bgView).offset(-55.0);
  41. make.height.equalTo(@24.0);
  42. }];
  43. [self.bgView addSubview:self.backBtn];
  44. [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.equalTo(self.bgView).offset(16.0);
  46. make.centerY.equalTo(self.titleLab.mas_centerY);
  47. make.height.width.equalTo(@24.0);
  48. }];
  49. [self.bgView addSubview:self.webView];
  50. [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.equalTo(self.bgView).offset(44.0);
  52. make.left.bottom.right.equalTo(self.bgView);
  53. }];
  54. [self addSubview:self.closeBtn];
  55. [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.left.right.equalTo(self);
  57. make.bottom.equalTo(self.bgView.mas_top);
  58. }];
  59. }
  60. - (void)showRulesWebBaseView{
  61. [self updateTheBgView];
  62. self.webView.webUrl = [NSURL URLWithString:self.urlStr];
  63. [self.webView toLoadTheUrl];
  64. CGRect actionViewRect = self.bgView.frame;
  65. actionViewRect.origin.x = SCREENWIDTH;
  66. self.bgView.frame = actionViewRect;
  67. WEAKSELF
  68. [UIView animateWithDuration:0.3 animations:^{
  69. CGRect actionViewRect = weakSelf.bgView.frame;
  70. actionViewRect.origin.x = 0;
  71. weakSelf.bgView.frame = actionViewRect;
  72. }];
  73. }
  74. - (void)dismissRulesWebBaseView{
  75. //完成下移动画
  76. WEAKSELF
  77. [UIView animateWithDuration:0.3 animations:^
  78. {
  79. CGRect actionSheetViewRect = weakSelf.bgView.frame;
  80. actionSheetViewRect.origin.x = SCREENWIDTH;
  81. weakSelf.bgView.frame = actionSheetViewRect;
  82. } completion:^(BOOL finished)
  83. {
  84. [self removeFromSuperview];
  85. }];
  86. }
  87. - (void)updateTheBgView{
  88. if(self.isHalfView){
  89. self.bgView.layer.cornerRadius = 16.0;
  90. self.bgView.layer.masksToBounds = YES;
  91. self.bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
  92. }
  93. [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
  94. make.height.equalTo(@(self.viewHieght));
  95. }];
  96. }
  97. #pragma mark - Lazy
  98. - (UIView *)bgView{
  99. if(!_bgView){
  100. _bgView = [[UIView alloc] init];
  101. _bgView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
  102. }
  103. return _bgView;
  104. }
  105. - (MOWebBaseView *)webView{
  106. if(!_webView){
  107. _webView = [[MOWebBaseView alloc] init];
  108. }
  109. return _webView;
  110. }
  111. - (BigBtn *)backBtn{
  112. if (!_backBtn) {
  113. _backBtn = [[BigBtn alloc] init];
  114. [_backBtn setImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] forState:UIControlStateNormal];
  115. [_backBtn addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
  116. }
  117. return _backBtn;
  118. }
  119. - (void)backButtonAction{
  120. [self dismissRulesWebBaseView];
  121. }
  122. - (UILabel *)titleLab{
  123. if(!_titleLab)
  124. {
  125. _titleLab = [UILabel new];
  126. _titleLab.textColor = kBaseTextColor_1;
  127. _titleLab.textAlignment = NSTextAlignmentCenter;
  128. _titleLab.font = [MOTextTools poppinsMediumFont:18.0];
  129. _titleLab.backgroundColor = [UIColor clearColor];
  130. _titleLab.text = NSLocalString(@"C60017");
  131. }
  132. return _titleLab;
  133. }
  134. - (UIButton *)closeBtn{
  135. if(!_closeBtn){
  136. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  137. [_closeBtn setTitle:@"" forState:UIControlStateNormal];
  138. [_closeBtn addTarget:self action:@selector(bgCloseBtnClickAction) forControlEvents:UIControlEventTouchUpInside];
  139. }
  140. return _closeBtn;
  141. }
  142. - (void)bgCloseBtnClickAction{
  143. [self dismissRulesWebBaseView];
  144. }
  145. @end