SPSBPopupADViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // SPSBPopupADViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/27.
  6. //
  7. #import "SPSBPopupADViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import <JXHSystemShortcut.h>
  10. #import "SPSBKeyProfile.h"
  11. #import "SPSBAppProfileModel.h"
  12. #import "SPSBHtmlViewController.h"
  13. #import "SPSBNavigationController.h"
  14. @interface SPSBPopupADViewController () {
  15. UIImageView *_imageView;
  16. UIButton *_dismissButton;
  17. bool _firstLoad;
  18. bool _completion;
  19. }
  20. @end
  21. @implementation SPSBPopupADViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self setupUI];
  25. _firstLoad = true;
  26. }
  27. - (void)viewWillAppear:(BOOL)animated {
  28. [super viewWillAppear:animated];
  29. if (_firstLoad) {
  30. _firstLoad = false;
  31. [jxh_userDefaults() setObject:_spsb_data.spsb_img forKey:SPSBPopupADImagePath];
  32. NSDate *new = [NSDate new];
  33. NSString *str = [jxh_dateFormatter() stringFromDate:new];
  34. [jxh_userDefaults() setObject:str forKey:SPSBPopupADTime];
  35. [jxh_userDefaults() synchronize];
  36. } else if (_completion) {
  37. [self dismissadPopoutView];
  38. }
  39. }
  40. #pragma mark - Action
  41. - (void)adPopoutAction {
  42. if ([_spsb_data.spsb_link hasPrefix:@"http"]) {
  43. @weakify(self)
  44. SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
  45. vc.spsb_url = _spsb_data.spsb_link;
  46. SPSBNavigationController *nav = [[SPSBNavigationController alloc] initWithRootViewController:vc];
  47. [self presentViewController:nav animated:true completion:^{
  48. @strongify(self)
  49. self->_completion = true;
  50. self->_imageView.hidden = true;
  51. self->_dismissButton.hidden = true;
  52. self.view.backgroundColor = [UIColor clearColor];
  53. }];
  54. }
  55. [self dismissadPopoutView];
  56. }
  57. - (void)dismissadPopoutView {
  58. [self hideAnimation:^(BOOL finished) {
  59. [self dismissViewControllerAnimated:false completion:^{
  60. if (self->_spsb_dismissComplete) {
  61. self->_spsb_dismissComplete();
  62. }
  63. }];
  64. }];
  65. }
  66. #pragma mark - UI
  67. - (void)setupUI {
  68. self.view.backgroundColor = spsb_000000_color(SPSBPopupViewBackgroundAlpha);
  69. [self addImageView];
  70. }
  71. - (void)addImageView {
  72. CGFloat width = jxh_screenWidth() - 62;
  73. CGFloat heidht = width / _spsb_image.size.width * _spsb_image.size.height;
  74. _imageView = [[UIImageView alloc] initWithImage:_spsb_image];
  75. [_imageView setLayerCornerRadius:8 clipToBounds:true];
  76. [self.view addSubview:_imageView];
  77. [_imageView makeConstraints:^(JXHConstraintMaker *make) {
  78. make.size.equalTo(CGSizeMake(width, heidht));
  79. make.centerX.equalTo(self.view);
  80. make.centerY.equalTo(self.view).offset(-32);
  81. }];
  82. _imageView.userInteractionEnabled = true;
  83. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adPopoutAction)];
  84. [_imageView addGestureRecognizer:tap];
  85. _dismissButton = [UIButton convenienceWithTarget:self action:@selector(dismissadPopoutView)];
  86. [_dismissButton setImage:jxh_getImage(close_ad) state:JXHButtonControlStateNormal];
  87. [self.view addSubview:_dismissButton];
  88. [_dismissButton makeConstraints:^(JXHConstraintMaker *make) {
  89. make.size.equalTo(CGSizeMake(64, 64));
  90. make.centerX.equalTo(self.view);
  91. make.top.equalTo(self->_imageView.bottom);
  92. }];
  93. }
  94. @end