123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //
- // SPSBPopupADViewController.m
- // 我的社保
- //
- // Created by shanp on 2021/4/27.
- //
- #import "SPSBPopupADViewController.h"
- #import "SPSBUIGeneralHeader.h"
- #import <JXHSystemShortcut.h>
- #import "SPSBKeyProfile.h"
- #import "SPSBAppProfileModel.h"
- #import "SPSBHtmlViewController.h"
- #import "SPSBNavigationController.h"
- @interface SPSBPopupADViewController () {
- UIImageView *_imageView;
- UIButton *_dismissButton;
- bool _firstLoad;
-
- bool _completion;
- }
- @end
- @implementation SPSBPopupADViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setupUI];
- _firstLoad = true;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (_firstLoad) {
- _firstLoad = false;
- [jxh_userDefaults() setObject:_spsb_data.spsb_img forKey:SPSBPopupADImagePath];
- NSDate *new = [NSDate new];
- NSString *str = [jxh_dateFormatter() stringFromDate:new];
- [jxh_userDefaults() setObject:str forKey:SPSBPopupADTime];
- [jxh_userDefaults() synchronize];
- } else if (_completion) {
- [self dismissadPopoutView];
- }
- }
- #pragma mark - Action
- - (void)adPopoutAction {
- if ([_spsb_data.spsb_link hasPrefix:@"http"]) {
- @weakify(self)
- SPSBHtmlViewController *vc = SPSBHtmlViewController.new;
- vc.spsb_url = _spsb_data.spsb_link;
- SPSBNavigationController *nav = [[SPSBNavigationController alloc] initWithRootViewController:vc];
- [self presentViewController:nav animated:true completion:^{
- @strongify(self)
- self->_completion = true;
- self->_imageView.hidden = true;
- self->_dismissButton.hidden = true;
- self.view.backgroundColor = [UIColor clearColor];
- }];
- }
- [self dismissadPopoutView];
- }
- - (void)dismissadPopoutView {
- [self hideAnimation:^(BOOL finished) {
- [self dismissViewControllerAnimated:false completion:^{
- if (self->_spsb_dismissComplete) {
- self->_spsb_dismissComplete();
- }
- }];
- }];
-
- }
- #pragma mark - UI
- - (void)setupUI {
- self.view.backgroundColor = spsb_000000_color(SPSBPopupViewBackgroundAlpha);
- [self addImageView];
- }
- - (void)addImageView {
- CGFloat width = jxh_screenWidth() - 62;
- CGFloat heidht = width / _spsb_image.size.width * _spsb_image.size.height;
-
- _imageView = [[UIImageView alloc] initWithImage:_spsb_image];
- [_imageView setLayerCornerRadius:8 clipToBounds:true];
- [self.view addSubview:_imageView];
- [_imageView makeConstraints:^(JXHConstraintMaker *make) {
- make.size.equalTo(CGSizeMake(width, heidht));
- make.centerX.equalTo(self.view);
- make.centerY.equalTo(self.view).offset(-32);
- }];
-
- _imageView.userInteractionEnabled = true;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adPopoutAction)];
- [_imageView addGestureRecognizer:tap];
-
- _dismissButton = [UIButton convenienceWithTarget:self action:@selector(dismissadPopoutView)];
- [_dismissButton setImage:jxh_getImage(close_ad) state:JXHButtonControlStateNormal];
- [self.view addSubview:_dismissButton];
- [_dismissButton makeConstraints:^(JXHConstraintMaker *make) {
- make.size.equalTo(CGSizeMake(64, 64));
- make.centerX.equalTo(self.view);
- make.top.equalTo(self->_imageView.bottom);
- }];
- }
- @end
|