| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // ComonWKWebViewController.m
- // AICity
- //
- // Created by 刘伟伟 on 2023/7/27.
- // Copyright © 2023 wei.z. All rights reserved.
- //
- #import "CommonBarView.h"
- #import "ComonWKWebViewController.h"
- #import <WebKit/WebKit.h>
- @interface ComonWKWebViewController ()
- @property(nonatomic,strong)CommonBarView *customerbar;
- @property (nonatomic, strong) WKWebView *webView;
- @end
- @implementation ComonWKWebViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = true;
- self.view.backgroundColor = rgba(18, 23, 41, 1);
- [self.view addSubview:self.customerbar];
- _customerbar.label.text=self.title;
- [self.view addSubview:self.webView];
- NSURL *url = [NSURL URLWithString:self.url];
- NSURLRequest *requset = [NSURLRequest requestWithURL:url];
- [self.webView loadRequest:requset];
- }
- -(WKWebView *)webView{
- if(!_webView){
- WKWebViewConfiguration *config = [WKWebViewConfiguration new];
- //初始化偏好设置属性:preferences
- config.preferences = [WKPreferences new];
- config.allowsInlineMediaPlayback = YES;
- //The minimum font size in points default is 0;
- config.preferences.minimumFontSize = 10;
- //是否支持JavaScript
- config.preferences.javaScriptEnabled = YES;
- //不通过用户交互,是否可以打开窗口
- config.preferences.javaScriptCanOpenWindowsAutomatically = NO;
-
- if (@available(iOS 10.0, *)) {
- config.mediaTypesRequiringUserActionForPlayback = NO;
- }
-
- _webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.customerbar.frame), SCREEN_WIDTH, kScreenHeight-CGRectGetMaxY(self.customerbar.frame)) configuration:config];
-
- }
- return _webView;
- }
- -(CommonBarView *)customerbar{
- if(!_customerbar){
- CGFloat h=0;
- if(@available(iOS 13.0, *)){
- UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
- CGRect f=sc.statusBarFrame;
- h=f.size.height;
- }else{
- h=[UIApplication sharedApplication].statusBarFrame.size.height;
- }
- if(h>=40){
- h=30;
- }
- _customerbar =[[CommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
- _customerbar.bgView.backgroundColor = [UIColor clearColor];
- _customerbar.label.text=@"我的收藏";
- _customerbar.bgView.alpha = 1;
- _customerbar.label.textColor = rgba(255, 255, 255, 1);
- // _customerbar.leftButton.hidden = true;
- // [_customerbar.leftButton setImage:[UIImage imageNamed:@"his_back"] forState:UIControlStateNormal];
- [_customerbar.rightButton setImage:[UIImage imageNamed:@"Frame 9411"] forState:UIControlStateNormal];
- [_customerbar.rightButton setTitle:@"编辑" forState:UIControlStateNormal];
- [_customerbar.rightButton setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateSelected];
- [_customerbar.rightButton setTitle:@"取消" forState:UIControlStateSelected];
- [_customerbar.rightButton setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal];
- _customerbar.rightButton.titleLabel.font =[UIFont systemFontOfSize:14];
- _customerbar.rightButton.hidden = true;
- [_customerbar.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [_customerbar.rightButton addTarget:self action:@selector(changeSelState:) forControlEvents:UIControlEventTouchUpInside];
- // [_customerbar.rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
- // [_customerbar.rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
- // make.centerY.equalTo(_customerbar.leftButton);
- // make.right.equalTo(_customerbar).offset(-15);
- // make.size.mas_equalTo(CGSizeMake(23, 23));
- // }];
- }
- return _customerbar;
- }
- -(void)backAction{
- [self.navigationController popViewControllerAnimated:true];
- [self dismissViewControllerAnimated:true completion:nil];
- }
- @end
|