Files
featherVoice/QXLive/Mine(音域)/View/亲密关系/QXHeartBeatLevelRuleView.m

124 lines
4.5 KiB
Mathematica
Raw Normal View History

2025-11-28 22:43:06 +08:00
//
// QXHeartBeatLevelRuleView.m
// QXLive
//
// Created by on 2025/11/22.
//
#import "QXHeartBeatLevelRuleView.h"
#import <WebKit/WebKit.h>
@interface QXHeartBeatLevelRuleView()
@property(nonatomic,strong)WKWebView *contentWebView;
@property(nonatomic,strong)UIView* bgView;
@property(nonatomic,strong)UIButton* closeBtn;
@end
@implementation QXHeartBeatLevelRuleView
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
self.bgView = [[UIView alloc] initWithFrame:CGRectMake((self.width-ScaleWidth(312))/2, (self.height-ScaleWidth(492))/2-40, ScaleWidth(312), ScaleWidth(492))];
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
[self addSubview:self.bgView];
[self.bgView addSubview:self.contentWebView];
self.closeBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.width-40)/2, self.bgView.bottom+10, 40, 40)];
[self.closeBtn setBackgroundImage:[UIImage imageNamed:@"home_white_close"] forState:(UIControlStateNormal)];
[self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.closeBtn];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(40);
make.centerX.equalTo(self);
make.top.mas_equalTo(self.bgView.bottom+10);
}];
}
-(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)closeAction{
[self hide];
}
#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(0, 0, self.bgView.width, self.bgView.height) configuration:configuration];
_contentWebView.backgroundColor = UIColor.clearColor;
[_contentWebView addRoundedCornersWithRadius:6];
_contentWebView.opaque = NO;
//
[_contentWebView sizeToFit];
_contentWebView.scrollView.showsVerticalScrollIndicator = NO;
_contentWebView.scrollView.backgroundColor = [UIColor clearColor];
_contentWebView.scrollView.bounces = NO;
//
}
return _contentWebView;
}
-(void)showInView:(UIView *)view{
self.bgView.y = -SCREEN_HEIGHT;
[view addSubview:self];
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = (self.height-ScaleWidth(492))/2-40;
} completion:^(BOOL finished) {
self.closeBtn.hidden = NO;
}];
}
-(void)hide{
self.closeBtn.hidden = YES;
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
@end