Files
featherVoice/QXLive/Mine(音域)/View/个人主页/QXDayTaskRuleView.m

139 lines
5.7 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// 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)UIProgressView *progressView;
@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 addSubview:self.progressView];
[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 {
2025-08-11 17:33:47 +08:00
NSString *urlStr = [NSString stringWithFormat:@"%@web/index.html#/pages/other/taskDesc",H5ServerUrl];
NSURL* url=[NSURL URLWithString:urlStr];
2025-08-08 10:49:36 +08:00
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[self.contentWebView loadRequest:request];
}
//
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
}
//KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:NSStringFromSelector(@selector(estimatedProgress))] && object == self.contentWebView) {
[self.progressView setAlpha:1.0f];
BOOL animated = self.contentWebView.estimatedProgress > self.progressView.progress;
[self.progressView setProgress:self.contentWebView.estimatedProgress animated:animated];
// Once complete, fade out UIProgressView
if(self.contentWebView.estimatedProgress >= 1.0f) {
[UIView animateWithDuration:0.3f delay:0.3f options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.progressView setAlpha:0.0f];
} completion:^(BOOL finished) {
[self.progressView setProgress:0.0f animated:NO];
}];
}
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
#pragma mark - getters and setters
- (WKWebView *)contentWebView {
if (!_contentWebView) {
//
WKWebViewConfiguration * configuration = [[WKWebViewConfiguration alloc]init];
//
configuration.selectionGranularity = YES;
// webpr
configuration.processPool = [[WKProcessPool alloc] init];
//, jsoc(OCURL)
WKUserContentController * UserContentController = [[WKUserContentController alloc]init];
//
configuration.suppressesIncrementalRendering = NO;
//
configuration.preferences.javaScriptEnabled = YES;
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.userContentController = UserContentController;
// iOS9iOS8
if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
//
configuration.allowsAirPlayForMediaPlayback = YES;
// 线
configuration.allowsInlineMediaPlayback = YES;
// NOios8
_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;
//kvo
[_contentWebView addObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress)) options:0 context:WKWebBrowserContext];
}
return _contentWebView;
}
- (UIProgressView *)progressView {
if (!_progressView) {
_progressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
_progressView.frame = CGRectMake(self.contentWebView.left+16, self.contentWebView.top, self.contentWebView.width-32, 2);
[_progressView setTrackTintColor:[UIColor colorWithRed:240.0/255 green:240.0/255 blue:240.0/255 alpha:1.0]];
_progressView.progressTintColor = QXConfig.themeColor;
}
return _progressView;
}
-(void)setProgressColor:(UIColor *)progressColor{
_progressView.progressTintColor = progressColor;
}
// dealloc
- (void)dealloc {
if (self) {
[self.contentWebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))];
}
}
@end