ComonWKWebViewController.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // ComonWKWebViewController.m
  3. // AICity
  4. //
  5. // Created by 刘伟伟 on 2023/7/27.
  6. // Copyright © 2023 wei.z. All rights reserved.
  7. //
  8. #import "CommonBarView.h"
  9. #import "ComonWKWebViewController.h"
  10. #import <WebKit/WebKit.h>
  11. @interface ComonWKWebViewController ()
  12. @property(nonatomic,strong)CommonBarView *customerbar;
  13. @property (nonatomic, strong) WKWebView *webView;
  14. @end
  15. @implementation ComonWKWebViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.fd_prefersNavigationBarHidden = true;
  19. self.view.backgroundColor = rgba(18, 23, 41, 1);
  20. [self.view addSubview:self.customerbar];
  21. _customerbar.label.text=self.title;
  22. [self.view addSubview:self.webView];
  23. NSURL *url = [NSURL URLWithString:self.url];
  24. NSURLRequest *requset = [NSURLRequest requestWithURL:url];
  25. [self.webView loadRequest:requset];
  26. }
  27. -(WKWebView *)webView{
  28. if(!_webView){
  29. WKWebViewConfiguration *config = [WKWebViewConfiguration new];
  30. //初始化偏好设置属性:preferences
  31. config.preferences = [WKPreferences new];
  32. config.allowsInlineMediaPlayback = YES;
  33. //The minimum font size in points default is 0;
  34. config.preferences.minimumFontSize = 10;
  35. //是否支持JavaScript
  36. config.preferences.javaScriptEnabled = YES;
  37. //不通过用户交互,是否可以打开窗口
  38. config.preferences.javaScriptCanOpenWindowsAutomatically = NO;
  39. if (@available(iOS 10.0, *)) {
  40. config.mediaTypesRequiringUserActionForPlayback = NO;
  41. }
  42. _webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.customerbar.frame), SCREEN_WIDTH, kScreenHeight-CGRectGetMaxY(self.customerbar.frame)) configuration:config];
  43. }
  44. return _webView;
  45. }
  46. -(CommonBarView *)customerbar{
  47. if(!_customerbar){
  48. CGFloat h=0;
  49. if(@available(iOS 13.0, *)){
  50. UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
  51. CGRect f=sc.statusBarFrame;
  52. h=f.size.height;
  53. }else{
  54. h=[UIApplication sharedApplication].statusBarFrame.size.height;
  55. }
  56. if(h>=40){
  57. h=30;
  58. }
  59. _customerbar =[[CommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
  60. _customerbar.bgView.backgroundColor = [UIColor clearColor];
  61. _customerbar.label.text=@"我的收藏";
  62. _customerbar.bgView.alpha = 1;
  63. _customerbar.label.textColor = rgba(255, 255, 255, 1);
  64. // _customerbar.leftButton.hidden = true;
  65. // [_customerbar.leftButton setImage:[UIImage imageNamed:@"his_back"] forState:UIControlStateNormal];
  66. [_customerbar.rightButton setImage:[UIImage imageNamed:@"Frame 9411"] forState:UIControlStateNormal];
  67. [_customerbar.rightButton setTitle:@"编辑" forState:UIControlStateNormal];
  68. [_customerbar.rightButton setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateSelected];
  69. [_customerbar.rightButton setTitle:@"取消" forState:UIControlStateSelected];
  70. [_customerbar.rightButton setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal];
  71. _customerbar.rightButton.titleLabel.font =[UIFont systemFontOfSize:14];
  72. _customerbar.rightButton.hidden = true;
  73. [_customerbar.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  74. [_customerbar.rightButton addTarget:self action:@selector(changeSelState:) forControlEvents:UIControlEventTouchUpInside];
  75. // [_customerbar.rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
  76. // [_customerbar.rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
  77. // make.centerY.equalTo(_customerbar.leftButton);
  78. // make.right.equalTo(_customerbar).offset(-15);
  79. // make.size.mas_equalTo(CGSizeMake(23, 23));
  80. // }];
  81. }
  82. return _customerbar;
  83. }
  84. -(void)backAction{
  85. [self.navigationController popViewControllerAnimated:true];
  86. [self dismissViewControllerAnimated:true completion:nil];
  87. }
  88. @end