美文网首页
2018-06-05自定义展示view的广告弹框

2018-06-05自定义展示view的广告弹框

作者: 破夕_____________ | 来源:发表于2018-06-05 09:32 被阅读13次
    实现类似的效果 手机截图

    自定义UIView

    //
    //  SXWADView.h
    //
    //  Created by  on 2018/6/4.
    //  Copyright © 2018年 . All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    typedef void(^CancelBlock)(BOOL isCancel);
    
    @interface SXWADView : UIView
    
    @property (nonatomic,strong) CancelBlock cancel_blcok;
    
    @end
    
    
    
    //
    //  SXWADView.m
    //
    //  Created by  on 2018/6/4.
    //  Copyright © 2018年 . All rights reserved.
    //
    
    #import "SXWADView.h"
    
    @interface SXWADView()<UIGestureRecognizerDelegate>
    @property (nonatomic,strong) UIButton * cancelBtn;
    @property (nonatomic,strong) UIImageView *imageView;
    @end
    
    
    @implementation SXWADView
    
    - (instancetype)initWithFrame:(CGRect)frame
    {
        if (self = [super initWithFrame:frame])
        {
            [self addSubViews];
            self.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.6];
    
        }
        return self;
    }
    
    - (void)addSubViews
    {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth - 630 * kScale)/2, (kScreenHeight - 900 * kScale)/2,630 * kScale,900 * kScale)];
        self.imageView.userInteractionEnabled = YES;
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://img.taopic.com/uploads/allimg/140516/234774-14051623055064.jpg"]];
        [self addSubview:self.imageView];
        
        UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView:)];
        PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
        PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
        PrivateLetterTap.delegate= self;
        self.imageView.contentMode = UIViewContentModeScaleToFill;
        [self.imageView addGestureRecognizer:PrivateLetterTap];
       
        
        self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.cancelBtn addTarget:self action:@selector(cancelButtonActionActionWithSender:) forControlEvents:UIControlEventTouchUpInside];
        [self.cancelBtn setBackgroundImage:[UIImage imageNamed:@"btn_close"] forState:UIControlStateNormal];
        [self addSubview:self.cancelBtn];
        [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make)
         {
             make.height.and.width.mas_equalTo(80 * kScale);
             make.centerX.equalTo(self);
             make.top.equalTo(self.imageView.mas_bottom).offset(20 * kScale);
         }];
    }
    - (void)tapAvatarView: (UITapGestureRecognizer *)gesture
    {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"SXWPushToSXWAdvert" object:nil userInfo:nil];
        [self removeAdvertView];
        JMLog(@"hjasgdijadkjashkhj");
        
    }
    // 移除广告页面
    - (void)removeAdvertView {
    
        [UIView animateWithDuration:0.3f animations:^{
            
            self.alpha = 0.f;
            
        } completion:^(BOOL finished) {
            
            [self removeFromSuperview];
            
        }];
        
    }
    
    //取消按钮的点击事件
    - (void)cancelButtonActionActionWithSender:(UIButton *)sender
    {
        if (self.cancel_blcok)
        {
            self.cancel_blcok(YES);
        }
    }
    
    
    @end
    
    
    

    HOME页面调起

    
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToSXWAd) name:@"SXWPushToSXWAdvert" object:nil];
    
    
    - (void)pushToSXWAd
    {
        if ([WGQJuMiUser shareInstance].uid == nil || [[WGQJuMiUser shareInstance].grade_id integerValue]<5)
        {
            [ZHWarnView showError:@"您无权跳转活动区"];
        }
        else
        {
            WGQActivityListViewController *adVc = [[WGQActivityListViewController alloc] init];
            adVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:adVc animated:YES];
        }
        
    }
    

    相关文章

      网友评论

          本文标题:2018-06-05自定义展示view的广告弹框

          本文链接:https://www.haomeiwen.com/subject/jlxpsftx.html