YOUPAILCBigCastProtocolVC.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // YOUPAILCBigCastProtocolVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/8/31.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCBigCastProtocolVC.h"
  9. #import "ZCBaseWebView.h"
  10. @interface YOUPAILCBigCastProtocolVC ()<ZCBaseWebViewDelegate>
  11. @property (nonatomic, strong) UIProgressView *youpaipprogressView;
  12. @property (nonatomic, strong) ZCBaseWebView *youpaipwebView;
  13. @property (nonatomic,strong)NSString *youpaipcontentUrl;
  14. @end
  15. @implementation YOUPAILCBigCastProtocolVC
  16. - (ZCBaseWebView *)youpaipwebView
  17. {
  18. if (!_youpaipwebView) {
  19. CGRect frame = CGRectMake(0, NavBarHeight, KScreenWidth,KScreenHeight-NavBarHeight-70-SafeHeight);
  20. _youpaipwebView = [[ZCBaseWebView alloc] initWithFrame:frame];
  21. _youpaipwebView.contentUrl = self.youpaipcontentUrl;
  22. _youpaipwebView.delegate = self;
  23. }
  24. return _youpaipwebView;
  25. }
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.youpaipcontentUrl = [NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,serviceH5];
  29. self.automaticallyAdjustsScrollViewInsets = NO;
  30. // self.view.backgroundColor = [UIColor clearColor];
  31. [self.view addSubview:self.youpaipwebView];
  32. self.title = @"相语欢颜女神服务协议";
  33. [self initProgress];
  34. [self.view addSubview:self.youpaipprogressView];
  35. [self.youpaipwebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.youpaipcontentUrl]]];
  36. if (@available(iOS 11.0, *)) {
  37. self.youpaipwebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  38. }
  39. UIButton* startBtn = [[UIButton alloc]initWithFrame:CGRectMake(40, KScreenHeight-60-SafeHeight, KScreenWidth-80, 50)];
  40. startBtn.backgroundColor = HexColorFromRGB(0x4F4B5B);
  41. startBtn.titleLabel.font = LCFont15;
  42. startBtn.layer.cornerRadius = 25.0;
  43. startBtn.layer.masksToBounds = YES;
  44. [startBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  45. [startBtn addTarget:self action:@selector(agreeClick) forControlEvents:(UIControlEventTouchUpInside)];
  46. [self.view addSubview:startBtn];
  47. if (self.youpaipagree) {
  48. [startBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  49. startBtn.userInteractionEnabled = NO;
  50. [startBtn setTitle:@"已同意女神服务协议" forState:(UIControlStateNormal)];
  51. }else{
  52. [startBtn setBackgroundImage:[LCTools ColorImage:startBtn.mj_size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight] forState:(UIControlStateNormal)];
  53. startBtn.userInteractionEnabled = YES;
  54. [startBtn setTitle:@"同意女神服务协议" forState:(UIControlStateNormal)];
  55. }
  56. }
  57. - (void)initProgress
  58. {
  59. CGRect barFrame = CGRectMake(0, NavBarHeight, KScreenWidth, 2.0f);
  60. self.youpaipprogressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
  61. self.youpaipprogressView.tintColor = [UIColor greenColor];
  62. self.youpaipprogressView.frame = barFrame;
  63. self.youpaipprogressView.transform = CGAffineTransformMakeScale(1.0f,2.0f);
  64. self.youpaipprogressView.backgroundColor = [UIColor clearColor];
  65. self.youpaipprogressView.trackTintColor=[UIColor clearColor];
  66. self.youpaipprogressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
  67. [self.youpaipprogressView setProgress:0 animated:NO];
  68. }
  69. #pragma mark hxwebview 的代理方法
  70. -(void)webViewDidFinishLoad:(ZCBaseWebView *)webView
  71. {
  72. self.title = self.youpaipwebView.title;
  73. }
  74. -(void)webView:(ZCBaseWebView *)webView updateProgress:(double)progress
  75. {
  76. [self.youpaipprogressView setProgress:progress animated:YES];
  77. if (progress>=1.f) {
  78. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  79. [self.youpaipprogressView setProgress:0 animated:NO];
  80. });
  81. }
  82. }
  83. -(void)webView:(ZCBaseWebView *)webView didFailLoadWithError:(NSError *)error
  84. {
  85. NSLog(@"error:%@",error);
  86. }
  87. - (void)viewWillAppear:(BOOL)animated
  88. {
  89. [super viewWillAppear:animated];
  90. self.navigationController.navigationBarHidden = NO;
  91. [self.view addSubview:self.youpaipprogressView];
  92. // 禁用返回手势
  93. self.sx_disableInteractivePop = YES;
  94. }
  95. -(void)viewWillDisappear:(BOOL)animated
  96. {
  97. [super viewWillDisappear:animated];
  98. if (self.youpaipneedHideNav) {
  99. self.navigationController.navigationBarHidden = YES;
  100. }else{
  101. self.navigationController.navigationBarHidden = NO;
  102. }
  103. // 开启返回手势
  104. self.sx_disableInteractivePop = NO;
  105. }
  106. - (void)dealloc{
  107. [_youpaipprogressView removeFromSuperview];
  108. [self.youpaipwebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
  109. }
  110. - (void)agreeClick{
  111. @weakify(self);
  112. [LCHttpHelper requestWithURLString:AgreeBigCastProtocol parameters:@{@"agreement":@1} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  113. @strongify(self);
  114. NSDictionary* dict = (NSDictionary*)responseObject;
  115. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  116. if (code==0) {
  117. // [ZCHUDHelper showTitle:@"已同意女神服务协议"];
  118. if (self.agreeProtocolBlock != nil) {
  119. self.agreeProtocolBlock();
  120. }
  121. // [self.navigationController popViewControllerAnimated:YES];
  122. }
  123. } failure:^(NSError *error) {
  124. }];
  125. }
  126. @end