Files
featherVoice/QXLive/活动/天空之境/QXSkyPraizeRuleView.m
2025-10-20 09:43:10 +08:00

135 lines
5.0 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// QXSkyPraizeRuleView.m
// QXLive
//
// Created by 启星 on 2025/8/26.
//
#import "QXSkyPraizeRuleView.h"
#import <WebKit/WebKit.h>
static void *WKWebBrowserContext = &WKWebBrowserContext;
@interface QXSkyPraizeRuleView()<WKNavigationDelegate,WKUIDelegate,UIGestureRecognizerDelegate>
@property(nonatomic,strong)WKWebView *contentWebView;
@property(nonatomic,strong)UIView* bgView;
@property(nonatomic,strong)UIImageView* ruleImageView;
@property(nonatomic,strong)UIImageView* bgImageView;
@end
@implementation QXSkyPraizeRuleView
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self initSubviews];
}
return self;
}
-(void)initSubviews{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
tap.delegate = self;
[self addGestureRecognizer:tap];
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(663))];
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
[self addSubview:self.bgView];
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sky_rule_bg"]];
self.bgImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(663));
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
[self.bgView addSubview:self.bgImageView];
self.ruleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sky_rule_icon"]];
self.ruleImageView.contentMode = UIViewContentModeScaleToFill;
self.ruleImageView.frame = CGRectMake((SCREEN_WIDTH-ScaleWidth(164))/2, 0, ScaleWidth(164), ScaleWidth(90));
[self.bgView addSubview:self.ruleImageView];
[self.bgView addSubview:self.contentWebView];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
return touch.view == self;
}
-(void)setRule:(NSString *)rule{
_rule = rule;
[self loadData];
}
- (void)loadData {
NSURL* url=[NSURL URLWithString:self.rule];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[self.contentWebView loadRequest:request];
}
//进度条
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
}
#pragma mark - getters and setters
- (WKWebView *)contentWebView {
if (!_contentWebView) {
//设置网页的配置文件
WKWebViewConfiguration * configuration = [[WKWebViewConfiguration alloc]init];
// 允许可以与网页交互,选择视图
configuration.selectionGranularity = YES;
// web内容处理池pr
configuration.processPool = [[WKProcessPool alloc] init];
//自定义配置,一般用于 js调用oc方法(OC拦截URL中的数据做自定义操作)
WKUserContentController * UserContentController = [[WKUserContentController alloc]init];
// 是否支持记忆读取
configuration.suppressesIncrementalRendering = NO;
// 允许用户更改网页的设置
configuration.preferences.javaScriptEnabled = YES;
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.userContentController = UserContentController;
// 此处一定要做判断因为是iOS9之后才有的方法否则在iOS8下会崩溃
if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
//允许视频播放
configuration.allowsAirPlayForMediaPlayback = YES;
// 允许在线播放
configuration.allowsInlineMediaPlayback = YES;
//开启手势触摸 默认设置就是NO。在ios8系统中会导致手势问题程序崩溃
_contentWebView.allowsBackForwardNavigationGestures = YES;
}
_contentWebView = [[WKWebView alloc] initWithFrame:CGRectMake(16, self.ruleImageView.bottom+12, self.width-16*2, self.bgView.height-self.ruleImageView.bottom-12) configuration:configuration];
_contentWebView.backgroundColor = RGB16A(0x000000, 0.5);
[_contentWebView addRoundedCornersWithRadius:6];
_contentWebView.opaque = NO;
//适应你设定的尺寸
[_contentWebView sizeToFit];
_contentWebView.scrollView.showsVerticalScrollIndicator = NO;
_contentWebView.scrollView.backgroundColor = [UIColor clearColor];
_contentWebView.scrollView.bounces = NO;
// 设置代理
_contentWebView.navigationDelegate = self;
}
return _contentWebView;
}
-(void)showInView:(UIView *)view{
self.bgView.y = SCREEN_HEIGHT;
[view addSubview:self];
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(663);
}];
}
-(void)hide{
// [self stopSlowAnimate];
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
@end