No Description

FKProServeDetailView.m 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // FKProServeDetailView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/8/16.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProServeDetailView.h"
  9. #import "FKTargetConfigUtil.h"
  10. #import "WebViewController.h"
  11. #import "FLControllerHelper.h"
  12. #import <WebKit/WebKit.h>
  13. @interface FKProServeDetailView ()
  14. <WKNavigationDelegate>
  15. @property (nonatomic, strong) UIView *contentView;
  16. @property (nonatomic, strong) UILabel *titleLabel;
  17. @property (nonatomic, strong) UIButton *cancelBtn;
  18. @property (nonatomic, strong) WKWebView *webview;
  19. @end
  20. @implementation FKProServeDetailView
  21. - (instancetype)initWithFrame:(CGRect)frame{
  22. if (self = [super initWithFrame:frame]) {
  23. self.backgroundColor = [UIColor whiteColor];
  24. [self addAllSubviews];
  25. [self addTapGesture];
  26. }
  27. return self;
  28. }
  29. - (void)requestWithURL:(NSURL *)url {
  30. if (url) {
  31. NSURLRequest *request = [NSURLRequest requestWithURL:url];
  32. [self.webview loadRequest:request];
  33. }
  34. }
  35. - (void)showInView:(UIView *)view animated:(BOOL)animated{
  36. if (!view) {
  37. return;
  38. }
  39. CGFloat height = view.frame.size.height;
  40. CGFloat width = view.frame.size.width;
  41. CGFloat contentH = 304; // 内容高度
  42. [view addSubview:self];
  43. [self setFrame:view.frame];
  44. [self.contentView setFrame:CGRectMake(0, height, width, contentH)];
  45. self.backgroundColor = [UIColor clearColor];
  46. CGFloat duration = animated ? 0.3f : 0;
  47. WeakSelf(weakSelf);
  48. [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
  49. weakSelf.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
  50. [weakSelf.contentView setFrame:CGRectMake(0, height - contentH, width, contentH)];
  51. } completion:nil];
  52. }
  53. - (void)dismissAnimated{
  54. if (self.superview){
  55. [UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
  56. self.backgroundColor = [UIColor clearColor];
  57. [self.contentView setFrame:CGRectOffset(self.contentView.frame, 0, CGRectGetHeight(self.contentView.frame))];
  58. } completion:^(BOOL finished) {
  59. [self removeFromSuperview];
  60. }];
  61. }
  62. }
  63. - (void)clickCancelBtn{
  64. [self dismissAnimated];
  65. }
  66. #pragma mark -
  67. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  68. NSURLRequest *request = navigationAction.request;
  69. NSRange range = [request.URL.absoluteString rangeOfString:@"new_webview" options:NSCaseInsensitiveSearch];
  70. if (range.length > 0) {
  71. decisionHandler(WKNavigationActionPolicyCancel);
  72. WebViewController *controller = [[WebViewController alloc] init];
  73. controller.url = request.URL.absoluteString;
  74. controller.hidesBottomBarWhenPushed = YES;
  75. [[FLControllerHelper currentNavigationController] pushViewController:controller
  76. animated:YES];
  77. } else {
  78. decisionHandler(WKNavigationActionPolicyAllow);
  79. }
  80. }
  81. #pragma mark - Gesture
  82. - (void)addTapGesture{
  83. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureClick:)];
  84. [self addGestureRecognizer:tap];
  85. }
  86. - (void)tapGestureClick:(UIGestureRecognizer *)tapGesture{
  87. CGPoint location = [tapGesture locationInView:self];
  88. BOOL isOnContent = CGRectContainsPoint(self.contentView.frame, location);
  89. if (isOnContent) {
  90. return;
  91. } else {
  92. [self clickCancelBtn];
  93. }
  94. }
  95. #pragma mark - Layout
  96. - (void)addAllSubviews{
  97. [self addSubview:self.contentView];
  98. [self.contentView addSubview:self.titleLabel];
  99. [self.contentView addSubview:self.cancelBtn];
  100. [self.contentView addSubview:self.webview];
  101. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.equalTo(self.contentView).offset(15);
  103. make.centerY.equalTo(self.contentView.mas_top).offset(22);
  104. }];
  105. [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.top.right.equalTo(self.contentView);
  107. make.size.mas_equalTo(CGSizeMake(45, 44));
  108. }];
  109. [self.webview mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.top.equalTo(self.contentView).offset(44);
  111. make.left.right.bottom.equalTo(self.contentView);
  112. }];
  113. }
  114. #pragma mark - Property
  115. - (WKWebView *)webview {
  116. if (!_webview) {
  117. _webview = [[WKWebView alloc] init];
  118. _webview.navigationDelegate = self;
  119. _webview.scrollView.showsHorizontalScrollIndicator = NO;
  120. _webview.backgroundColor = [UIColor whiteColor];
  121. }
  122. return _webview;
  123. }
  124. - (UILabel *)titleLabel{
  125. if (_titleLabel == nil) {
  126. _titleLabel = [[UILabel alloc]init];
  127. _titleLabel.font = [UIFont systemFontOfSize:14];
  128. _titleLabel.textColor = UIColorFromRGB(0x999999);
  129. _titleLabel.text = @"服务说明";
  130. }
  131. return _titleLabel;
  132. }
  133. - (UIButton *)cancelBtn{
  134. if (_cancelBtn == nil) {
  135. _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  136. [_cancelBtn setImage:[UIImage imageNamed:@"shareCancel"] forState:UIControlStateNormal];
  137. [_cancelBtn addTarget:self
  138. action:@selector(clickCancelBtn)
  139. forControlEvents:UIControlEventTouchUpInside];
  140. }
  141. return _cancelBtn;
  142. }
  143. - (UIView *)contentView{
  144. if (_contentView == nil) {
  145. _contentView = [[UIView alloc]init];
  146. _contentView.backgroundColor = [UIColor whiteColor];
  147. }
  148. return _contentView;
  149. }
  150. @end