Files
featherVoice/QXLive/Mine(音域)/View/亲密关系/QXHeartBeatLevelRuleView.m
2025-11-28 22:43:06 +08:00

124 lines
4.5 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.

//
// 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;
// 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(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