Commit 07391206d49a0feefcd1b80b43b4367252e298f4
1 parent
db8e345b
no message
Showing
2 changed files
with
205 additions
and
0 deletions
CNLiveIntegralModule/Classes/Tools/CNLiveRewardRulesView.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveRewardRulesView.h | |
| 3 | +// CNLiveIntegralModule | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/3/1. | |
| 6 | +// Copyright © 2019年 cnlive. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | + | |
| 13 | +@interface CNLiveRewardRulesView : UIView | |
| 14 | + | |
| 15 | ++ (void)showRewardRulesView; | |
| 16 | ++ (void)showRewardRulesView:(NSString *)url; | |
| 17 | + | |
| 18 | +@end | |
| 19 | + | |
| 20 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveIntegralModule/Classes/Tools/CNLiveRewardRulesView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveRewardRulesView.m | |
| 3 | +// CNLiveIntegralModule | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/3/1. | |
| 6 | +// Copyright © 2019年 cnlive. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveRewardRulesView.h" | |
| 10 | +#import <WebKit/WebKit.h> | |
| 11 | +#import "QMUIKit.h" | |
| 12 | +#import "YYKit.h" | |
| 13 | +#import <Masonry/Masonry.h> | |
| 14 | + | |
| 15 | +#import "CNLiveGoldWhereaboutsView.h" | |
| 16 | + | |
| 17 | +@interface CNLiveRewardRulesView()<WKNavigationDelegate,WKUIDelegate> | |
| 18 | +@property (nonatomic, strong) UIImageView *bgView; | |
| 19 | +@property (nonatomic, strong) UIButton *closeBtn; | |
| 20 | +@property (nonatomic, strong) WKWebView *webView; | |
| 21 | + | |
| 22 | +@end | |
| 23 | + | |
| 24 | +@implementation CNLiveRewardRulesView | |
| 25 | +static const NSInteger margin = 0; | |
| 26 | + | |
| 27 | +#pragma mark - Using Method | |
| 28 | ++ (void)showRewardRulesView:(NSString *)url{ | |
| 29 | + CNLiveRewardRulesView *view = [[CNLiveRewardRulesView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; | |
| 30 | + view.backgroundColor = [UIColor colorWithWhite:0.2f alpha:0.4f]; | |
| 31 | + [view.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]]; | |
| 32 | + [[UIApplication sharedApplication].keyWindow addSubview:view]; | |
| 33 | + | |
| 34 | +} | |
| 35 | ++ (void)showRewardRulesView{ | |
| 36 | + CNLiveRewardRulesView *view = [[CNLiveRewardRulesView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; | |
| 37 | + view.backgroundColor = [UIColor colorWithWhite:0.2f alpha:0.4f]; | |
| 38 | + [[UIApplication sharedApplication].keyWindow addSubview:view]; | |
| 39 | + | |
| 40 | +} | |
| 41 | +#pragma mark - Init | |
| 42 | +- (instancetype)initWithFrame:(CGRect)frame { | |
| 43 | + self = [super initWithFrame:frame]; | |
| 44 | + if (self) { | |
| 45 | + [self setup]; | |
| 46 | + } | |
| 47 | + return self; | |
| 48 | +} | |
| 49 | +#pragma mark - UI | |
| 50 | +- (void)setup { | |
| 51 | + [self addSubview:self.bgView]; | |
| 52 | + [self.bgView addSubview:self.closeBtn]; | |
| 53 | + [self.bgView addSubview:self.webView]; | |
| 54 | + [self addAnimation]; | |
| 55 | + | |
| 56 | +} | |
| 57 | +- (void)layoutSubviews{ | |
| 58 | + [super layoutSubviews]; | |
| 59 | + [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 60 | + make.centerX.equalTo(self.mas_centerX).with.offset(0); | |
| 61 | + make.centerY.equalTo(self.mas_centerY).with.offset(0); | |
| 62 | + make.width.offset(320*(SCREEN_WIDTH/375.0)); | |
| 63 | + make.height.offset(320*(SCREEN_WIDTH/375.0)*454/320.0); | |
| 64 | + | |
| 65 | + }]; | |
| 66 | + | |
| 67 | + [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 68 | + make.centerX.equalTo(_bgView.mas_centerX).with.offset(0); | |
| 69 | + make.bottom.equalTo(_bgView.mas_bottom).with.offset(-0); | |
| 70 | + make.width.offset(100*(SCREEN_WIDTH/375.0)); | |
| 71 | + make.height.offset(56*(SCREEN_WIDTH/375.0)); | |
| 72 | + | |
| 73 | + }]; | |
| 74 | + | |
| 75 | + [_webView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 76 | + make.top.equalTo(_bgView.mas_top).with.offset(margin); | |
| 77 | + make.left.equalTo(_bgView.mas_left).with.offset(margin); | |
| 78 | + make.right.equalTo(_bgView.mas_right).with.offset(-margin); | |
| 79 | + make.bottom.equalTo(_closeBtn.mas_top).with.offset(margin); | |
| 80 | + | |
| 81 | + }]; | |
| 82 | + | |
| 83 | +} | |
| 84 | +#pragma mark - Data | |
| 85 | +#pragma mark - Private Methods | |
| 86 | +- (void)addAnimation{ | |
| 87 | + _bgView.transform = CGAffineTransformMake(0.01, 0, 0, 0.01, _bgView.left, _bgView.top); | |
| 88 | + [UIView animateWithDuration:0.3f animations:^{ | |
| 89 | + self->_bgView.transform = CGAffineTransformMake(1.05f, 0, 0, 1.0f, 0, 0); | |
| 90 | + | |
| 91 | + } completion:^(BOOL finished) { | |
| 92 | + [UIView animateWithDuration:0.1f animations:^{ | |
| 93 | + self->_bgView.transform = CGAffineTransformMake(1, 0, 0, 1, 0, 0); | |
| 94 | + | |
| 95 | + } completion:^(BOOL finished) { | |
| 96 | + // 恢复原位 | |
| 97 | + self->_bgView.transform = CGAffineTransformIdentity; | |
| 98 | + | |
| 99 | + }]; | |
| 100 | + | |
| 101 | + }]; | |
| 102 | + | |
| 103 | +} | |
| 104 | +- (void)hiddenAction{ | |
| 105 | + _bgView.layer.transform = CATransform3DMakeScale(1, 1, 1); | |
| 106 | + | |
| 107 | + [UIView animateWithDuration:0.3f animations:^{ | |
| 108 | + // 按照比例scalex=0.001,y=0.001进行缩小 | |
| 109 | + _bgView.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1); | |
| 110 | + | |
| 111 | + } completion:^(BOOL finished) { | |
| 112 | + [self removeFromSuperview]; | |
| 113 | + | |
| 114 | + }]; | |
| 115 | + | |
| 116 | + for (UIView *view in [UIApplication sharedApplication].keyWindow.subviews) { | |
| 117 | + if([view isKindOfClass:[CNLiveGoldWhereaboutsView class]]){ | |
| 118 | + [view removeFromSuperview]; | |
| 119 | + | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 123 | +} | |
| 124 | + | |
| 125 | +/* | |
| 126 | + // Only override drawRect: if you perform custom drawing. | |
| 127 | + // An empty implementation adversely affects performance during animation. | |
| 128 | + - (void)drawRect:(CGRect)rect { | |
| 129 | + // Drawing code | |
| 130 | + } | |
| 131 | + */ | |
| 132 | +#pragma mark - Action | |
| 133 | +- (void)clickCloseBtn:(UIButton *)btn{ | |
| 134 | + [self hiddenAction]; | |
| 135 | + | |
| 136 | +} | |
| 137 | + | |
| 138 | +#pragma mark - Lazy loading | |
| 139 | +- (UIImageView *)bgView{ | |
| 140 | + if (!_bgView) { | |
| 141 | + _bgView = [[UIImageView alloc] init]; | |
| 142 | + _bgView.userInteractionEnabled = YES; | |
| 143 | + _bgView.backgroundColor = [UIColor whiteColor]; | |
| 144 | + _bgView.layer.cornerRadius = 25*(SCREEN_WIDTH/375.0); | |
| 145 | + _bgView.layer.masksToBounds = YES; | |
| 146 | + | |
| 147 | + } | |
| 148 | + return _bgView; | |
| 149 | +} | |
| 150 | +- (WKWebView *)webView { | |
| 151 | + if (_webView == nil) { | |
| 152 | + WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc]init]; | |
| 153 | + config.preferences = [WKPreferences new]; | |
| 154 | + config.preferences.javaScriptEnabled = YES; | |
| 155 | + config.preferences.minimumFontSize = 15; | |
| 156 | + config.preferences.javaScriptCanOpenWindowsAutomatically = YES; | |
| 157 | + config.userContentController = [[WKUserContentController alloc]init]; | |
| 158 | + _webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config]; | |
| 159 | + _webView.navigationDelegate = self; | |
| 160 | + _webView.UIDelegate = self; | |
| 161 | + _webView.scrollView.bounces = NO; | |
| 162 | + _webView.scrollView.exclusiveTouch = NO; | |
| 163 | + _webView.scrollView.showsVerticalScrollIndicator = NO; | |
| 164 | + _webView.scrollView.showsHorizontalScrollIndicator = NO; | |
| 165 | + _webView.layer.cornerRadius = 25*(SCREEN_WIDTH/375.0); | |
| 166 | + _webView.layer.masksToBounds = YES; | |
| 167 | + | |
| 168 | + } | |
| 169 | + return _webView; | |
| 170 | +} | |
| 171 | +- (UIButton *)closeBtn{ | |
| 172 | + if(_closeBtn == nil){ | |
| 173 | + _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 174 | + _closeBtn.titleLabel.font = UIFontMake(15); | |
| 175 | + [_closeBtn addTarget:self action:@selector(clickCloseBtn:) forControlEvents:UIControlEventTouchUpInside]; | |
| 176 | + [_closeBtn setTitle:@"我知道了" forState:UIControlStateNormal]; | |
| 177 | + [_closeBtn setTitleColor:[UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0] forState:UIControlStateNormal]; | |
| 178 | + _closeBtn.adjustsImageWhenHighlighted = NO; | |
| 179 | + | |
| 180 | + } | |
| 181 | + return _closeBtn; | |
| 182 | + | |
| 183 | +} | |
| 184 | + | |
| 185 | +@end | ... | ... |