98 lines
3.7 KiB
Objective-C
98 lines
3.7 KiB
Objective-C
//
|
||
// QXDayTaskRuleView.m
|
||
// QXLive
|
||
//
|
||
// Created by 启星 on 2025/6/6.
|
||
//
|
||
|
||
#import "QXDayTaskRuleView.h"
|
||
#import <WebKit/WebKit.h>
|
||
static void *WKWebBrowserContext = &WKWebBrowserContext;
|
||
|
||
@interface QXDayTaskRuleView()<WKNavigationDelegate,WKUIDelegate>
|
||
@property(nonatomic,strong)WKWebView *contentWebView;
|
||
@property(nonatomic,strong)UIButton* closeBtn;
|
||
@end
|
||
|
||
@implementation QXDayTaskRuleView
|
||
|
||
- (instancetype)initWithFrame:(CGRect)frame
|
||
{
|
||
self = [super initWithFrame:frame];
|
||
if (self) {
|
||
[self initSubviews];
|
||
}
|
||
return self;
|
||
}
|
||
-(void)initSubviews{
|
||
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
|
||
[self addSubview:self.contentWebView];
|
||
[self loadData];
|
||
|
||
self.closeBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.width-30)/2, self.contentWebView.bottom+10, 30, 30)];
|
||
[self.closeBtn setBackgroundImage:[UIImage imageNamed:@"home_white_close"] forState:(UIControlStateNormal)];
|
||
[self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
[self addSubview:self.closeBtn];
|
||
}
|
||
-(void)closeAction{
|
||
[self removeFromSuperview];
|
||
}
|
||
- (void)loadData {
|
||
NSString *urlStr = [NSString stringWithFormat:@"%@web/index.html#/pages/other/taskDesc",H5ServerUrl];
|
||
NSURL* url=[NSURL URLWithString:urlStr];
|
||
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(25, NavContentHeight+40, self.width-25*2, self.height-(NavContentHeight+40)*2-30) configuration:configuration];
|
||
_contentWebView.backgroundColor = [UIColor clearColor];
|
||
[_contentWebView addRoundedCornersWithRadius:16];
|
||
_contentWebView.opaque = NO;
|
||
//适应你设定的尺寸
|
||
[_contentWebView sizeToFit];
|
||
_contentWebView.scrollView.showsVerticalScrollIndicator = NO;
|
||
_contentWebView.scrollView.backgroundColor = [UIColor clearColor];
|
||
_contentWebView.scrollView.bounces = NO;
|
||
// 设置代理
|
||
_contentWebView.navigationDelegate = self;
|
||
}
|
||
return _contentWebView;
|
||
}
|
||
|
||
|
||
|
||
@end
|