Files
featherVoice/QXLive/Mine(音域)/View/钱包/QXWalletRuleView.m
启星 f0c82c3ac7 1.1.2
2025-11-03 09:55:25 +08:00

152 lines
5.8 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.

//
// QXWalletRuleView.m
// QXLive
//
// Created by 启星 on 2025/10/31.
//
#import "QXWalletRuleView.h"
#import <WebKit/WebKit.h>
@interface QXWalletRuleView()
@property(nonatomic,strong)WKWebView *contentWebView;
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UIButton *cancelBtn;
@property (nonatomic,strong)UIButton *commitBtn;
@end
@implementation QXWalletRuleView
- (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.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
self.bgView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-ScaleWidth(350))/2.0, -self.height, ScaleWidth(350), ScaleWidth(550))];
self.bgView.backgroundColor = [UIColor whiteColor];
self.bgView.layer.masksToBounds = YES;
self.bgView.layer.cornerRadius = 16;
[self addSubview:self.bgView];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
self.titleLabel.text = QXText(@"温馨提示");
self.titleLabel.textColor = RGB16(0x333333);
[self.bgView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.bgView);
make.top.equalTo(self.bgView).offset(16);
make.height.mas_equalTo(24);
}];
self.commitBtn = [[UIButton alloc] init];
[self.commitBtn addRoundedCornersWithRadius:21];
self.commitBtn.backgroundColor = QXConfig.themeColor;
[self.commitBtn setTitle:QXText(@"我知道了") forState:(UIControlStateNormal)];
[self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.commitBtn addTarget:self action:@selector(cancelAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.bgView addSubview:self.commitBtn];
[self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bgView).offset(-12);
make.height.mas_equalTo(42);
make.width.mas_equalTo(ScaleWidth(110));
make.centerX.equalTo(self.bgView);
}];
[self.bgView addSubview:self.contentWebView];
[self.contentWebView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
make.bottom.equalTo(self.commitBtn.mas_top).offset(-10);
make.left.mas_equalTo(16);
make.right.mas_equalTo(-16);
}];
[self loadData];
}
-(void)cancelAction{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kWalletRuleHide];
if (self.toWalletBlock) {
self.toWalletBlock();
}
[self hide];
}
- (void)loadData {
NSString *urlStr = [NSString stringWithFormat:@"%@api/Page/page_show?id=28",ServerUrl];
NSURL* url=[NSURL URLWithString:urlStr];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[self.contentWebView loadRequest:request];
}
-(void)showInView:(UIView *)view{
[view addSubview:self];
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.bgView.y = (SCREEN_HEIGHT-ScaleWidth(550))/2.0;
} completion:^(BOOL finished) {
}];
}
-(void)hide{
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.bgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
#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, 0, self.width-25*2, self.height-(NavContentHeight+40)*2-30) configuration:configuration];
_contentWebView.backgroundColor = [UIColor clearColor];
_contentWebView.opaque = NO;
//适应你设定的尺寸
[_contentWebView sizeToFit];
_contentWebView.scrollView.showsVerticalScrollIndicator = NO;
_contentWebView.scrollView.backgroundColor = [UIColor clearColor];
_contentWebView.scrollView.bounces = NO;
}
return _contentWebView;
}
@end