123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- //
- // FKProServeDetailView.m
- // FirstLink
- //
- // Created by jack on 16/8/16.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKProServeDetailView.h"
- #import "FKTargetConfigUtil.h"
- #import "WebViewController.h"
- #import "FLControllerHelper.h"
- #import <WebKit/WebKit.h>
- @interface FKProServeDetailView ()
- <WKNavigationDelegate>
- @property (nonatomic, strong) UIView *contentView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UIButton *cancelBtn;
- @property (nonatomic, strong) WKWebView *webview;
- @end
- @implementation FKProServeDetailView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor whiteColor];
-
- [self addAllSubviews];
- [self addTapGesture];
- }
- return self;
- }
- - (void)requestWithURL:(NSURL *)url {
- if (url) {
- NSURLRequest *request = [NSURLRequest requestWithURL:url];
- [self.webview loadRequest:request];
- }
- }
- - (void)showInView:(UIView *)view animated:(BOOL)animated{
- if (!view) {
- return;
- }
- CGFloat height = view.frame.size.height;
- CGFloat width = view.frame.size.width;
- CGFloat contentH = 304; // 内容高度
-
- [view addSubview:self];
- [self setFrame:view.frame];
- [self.contentView setFrame:CGRectMake(0, height, width, contentH)];
-
- self.backgroundColor = [UIColor clearColor];
-
- CGFloat duration = animated ? 0.3f : 0;
- WeakSelf(weakSelf);
- [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
- weakSelf.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
- [weakSelf.contentView setFrame:CGRectMake(0, height - contentH, width, contentH)];
- } completion:nil];
-
- }
- - (void)dismissAnimated{
- if (self.superview){
- [UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
- self.backgroundColor = [UIColor clearColor];
- [self.contentView setFrame:CGRectOffset(self.contentView.frame, 0, CGRectGetHeight(self.contentView.frame))];
- } completion:^(BOOL finished) {
- [self removeFromSuperview];
- }];
- }
- }
- - (void)clickCancelBtn{
- [self dismissAnimated];
- }
- #pragma mark -
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
- NSURLRequest *request = navigationAction.request;
- NSRange range = [request.URL.absoluteString rangeOfString:@"new_webview" options:NSCaseInsensitiveSearch];
- if (range.length > 0) {
- decisionHandler(WKNavigationActionPolicyCancel);
-
- WebViewController *controller = [[WebViewController alloc] init];
- controller.url = request.URL.absoluteString;
- controller.hidesBottomBarWhenPushed = YES;
- [[FLControllerHelper currentNavigationController] pushViewController:controller
- animated:YES];
- } else {
- decisionHandler(WKNavigationActionPolicyAllow);
- }
- }
- #pragma mark - Gesture
- - (void)addTapGesture{
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureClick:)];
- [self addGestureRecognizer:tap];
- }
- - (void)tapGestureClick:(UIGestureRecognizer *)tapGesture{
- CGPoint location = [tapGesture locationInView:self];
- BOOL isOnContent = CGRectContainsPoint(self.contentView.frame, location);
- if (isOnContent) {
- return;
- } else {
- [self clickCancelBtn];
- }
- }
- #pragma mark - Layout
- - (void)addAllSubviews{
-
- [self addSubview:self.contentView];
- [self.contentView addSubview:self.titleLabel];
- [self.contentView addSubview:self.cancelBtn];
- [self.contentView addSubview:self.webview];
-
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.centerY.equalTo(self.contentView.mas_top).offset(22);
- }];
-
- [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.right.equalTo(self.contentView);
- make.size.mas_equalTo(CGSizeMake(45, 44));
- }];
-
- [self.webview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(44);
- make.left.right.bottom.equalTo(self.contentView);
- }];
- }
- #pragma mark - Property
- - (WKWebView *)webview {
- if (!_webview) {
- _webview = [[WKWebView alloc] init];
- _webview.navigationDelegate = self;
- _webview.scrollView.showsHorizontalScrollIndicator = NO;
- _webview.backgroundColor = [UIColor whiteColor];
- }
- return _webview;
- }
- - (UILabel *)titleLabel{
- if (_titleLabel == nil) {
- _titleLabel = [[UILabel alloc]init];
- _titleLabel.font = [UIFont systemFontOfSize:14];
- _titleLabel.textColor = UIColorFromRGB(0x999999);
- _titleLabel.text = @"服务说明";
- }
- return _titleLabel;
- }
- - (UIButton *)cancelBtn{
- if (_cancelBtn == nil) {
- _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_cancelBtn setImage:[UIImage imageNamed:@"shareCancel"] forState:UIControlStateNormal];
- [_cancelBtn addTarget:self
- action:@selector(clickCancelBtn)
- forControlEvents:UIControlEventTouchUpInside];
-
- }
- return _cancelBtn;
- }
- - (UIView *)contentView{
- if (_contentView == nil) {
- _contentView = [[UIView alloc]init];
- _contentView.backgroundColor = [UIColor whiteColor];
- }
- return _contentView;
- }
- @end
|