123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763 |
- //
- // DYAdAlertView.m
- // DYAdAlertViewApp
- //
- // Created by Daniel Yao on 16/12/16.
- // Copyright © 2016年 Daniel Yao. All rights reserved.
- //
- #define BaseTag 100
- #define ScreenBounds [UIScreen mainScreen].bounds
- #define ScreenWidth [UIScreen mainScreen].bounds.size.width
- #define ScreenHeight [UIScreen mainScreen].bounds.size.height
- #define ScrollWidth _scrollView.frame.size.width
- #define ScrollHeight _scrollView.frame.size.height
- #import "DYAdAlertView.h"
- #import "DYAdModel.h"
- #import "FLAnimatedImageView.h"
- #import "FLAnimatedImage.h"
- #import "SimpleAudioPlayer.h"
- #import <Lottie/Lottie.h>
- @interface DYAdAlertView()<UIScrollViewDelegate>
- {
- UIPageControl *pageControl;
- UIButton *cancelBtn;
- NSString *placeHolderImgStr;
-
-
- }
- @property(nonatomic,strong)UIScrollView *scrollView;
- @property(nonatomic,assign)NSInteger itemsCount;
- @property(nonatomic,strong)NSArray *adDataList;
- @property(nonatomic,assign)BOOL hiddenPageControl;
- @property(nonatomic, strong)NSTimer *timer;
- @property(nonatomic, strong)JXAudioPlayer *audioPlayer;
- @property(nonatomic,assign)int currentTime;
- @property (nonatomic,weak) UIImageView *animatedImageView;
- @property (nonatomic,weak) CABasicAnimation *animaaaa;
- @property (nonatomic,weak) LOTAnimationView *animation;
- @end
- @implementation DYAdAlertView
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- - (JXAudioPlayer *)audioPlayer {
- if (!_audioPlayer) {
- _audioPlayer = [[JXAudioPlayer alloc] init];
- }
- return _audioPlayer;
- }
- +(DYAdAlertView *)showInView:(UIView *)view theDelegate:(id)delegate theADInfo: (NSArray *)dataList placeHolderImage: (NSString *)placeHolderStr{
- if (!dataList) {
- return nil;
- }
-
- DYAdAlertView *sqAlertView = [[DYAdAlertView alloc] initShowInView:view theDelegate:delegate theADInfo:dataList placeHolderImage:placeHolderStr];
- return sqAlertView;
- }
- -(DYAdAlertView *)showInViewSelf:(UIView *)view theDelegate:(id)delegate theADInfo: (NSArray *)dataList placeHolderImage: (NSString *)placeHolderStr{
-
- DYAdAlertView *sqAlertView = [self initShowInView:view theDelegate:delegate theADInfo:dataList placeHolderImage:placeHolderStr];
-
- return sqAlertView;
- }
- - (instancetype)initShowInView:(UIView *)view theDelegate:(id)delegate
- theADInfo:(NSArray *)dataList
- placeHolderImage: (NSString *)placeHolderStr{
- self = [super init];
- if (self) { //修改的龙
- _currentTime=0;
- self.userInteractionEnabled=YES;
- self.frame = [UIScreen mainScreen].bounds;
- //self.frame = CGRectMake(100,(ScreenHeight/2)-ScreenHeight/4, ScreenWidth-200, ScreenHeight/2);
- self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
- placeHolderImgStr = placeHolderStr;
- self.delegate = delegate;
- self.hiddenPageControl = NO;
- self.adDataList = dataList;
-
- // [[[UIApplication sharedApplication].windows objectAtIndex:0] endEditing:YES];
- // [[[UIApplication sharedApplication].windows objectAtIndex:0] addSubview:self];
- //
-
- [self showAlertAnimation];
- //UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeFromCurrentView:)];
- // [self addGestureRecognizer:tapGesture];
- }
- return self;
- }
- - (void)showAlertAnimation
- {
- CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
- animation.fromValue = [NSNumber numberWithFloat:0];
- animation.toValue = [NSNumber numberWithFloat:1];
- animation.duration = 0.25;
- animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
- [self.layer addAnimation:animation forKey:@"opacity"];
- DYAdModel *adModel = self.adDataList[0];
- if (adModel.audio.length>1) {
-
- [SimpleAudioPlayer stopAllPlayers];
- [SimpleAudioPlayer playFile:@"houjiao.mp3"];
-
-
- }
- _currentTime=adModel.duration;
- if (adModel.duration>0) {
- if (adModel.type == DYAdModelTypeGifttOpenAnimation) {
- // _timer = [NSTimer scheduledTimerWithTimeInterval:_currentTime target:self selector:@selector(tapContentImgViewaaa:) userInfo:nil repeats:NO];
- // [[NSRunLoop mainRunLoop] addTimer:_timer forMode: NSRunLoopCommonModes];
- }else {
- // _timer = [NSTimer scheduledTimerWithTimeInterval:adModel.duration target:self selector:@selector(removeSelfFromSuperview) userInfo:nil repeats:NO];
- // [[NSRunLoop mainRunLoop] addTimer:_timer forMode: NSRunLoopCommonModes];
- }
- } else {
-
- }
- }
-
- -(void)dealloc{
- _audioPlayer.delegate = nil;
- }
- -(void)removeFromCurrentView:(UIGestureRecognizer *)gesture
- {
- UIView * subView = (UIView *)[self viewWithTag:99];
- UIView * shadowView = self;
- if (CGRectContainsPoint(subView.frame, [gesture locationInView:shadowView]))
- {}else{
- [self removeSelfFromSuperview];
- }
- }
- - (void)removeSelfFromSuperview
- {
- [UIView animateWithDuration:0.2 animations:^{
- self.alpha = 0;
- } completion:^(BOOL finished) {
- [self removeFromSuperview];
- // 停止定时器
- [_timer invalidate];
- _timer = nil;
- }];
- }
- -(UIScrollView *)scrollView{
- if (!_scrollView) {
- _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, ScreenHeight/2-600/2, ScreenWidth, 600)];
- _scrollView.backgroundColor = [UIColor clearColor];
- _scrollView.userInteractionEnabled = YES;
- _scrollView.contentSize = CGSizeMake(self.frame.size.width*_itemsCount, 410);
- _scrollView.delegate = self;
- _scrollView.pagingEnabled = YES;
- _scrollView.bounces = YES;
- _scrollView.showsHorizontalScrollIndicator = NO;
- }
- return _scrollView;
- }
- -(void)setAdDataList:(NSArray *)adDataList{
-
- _adDataList = adDataList;
- _itemsCount = adDataList.count;
-
- [self creatItemView];
- }
- -(void)creatItemView{
-
- if (_itemsCount == 0) {
- return;
- }
- if (_itemsCount == 1) {
- self.hiddenPageControl = YES;
- }
- [self addSubview:self.scrollView];
-
- DYAdModel *adModel = [_adDataList objectAtIndex:0];
-
- typedef NS_ENUM(NSUInteger, DYAdModelType) {
- DYAdModelTypeLongAnimation = 0, // 龙动画
- DYAdModelTypeGiftOpen, // 宝箱打开
- DYAdModelTypeGifttOpenAnimation, // 宝箱动画
- DYAdModelTypeGiftAfterOpen, // 宝箱打开后
- DYAdModelTypePackRedOpen, // 红包打开后
- };
- _timer=nil;
- [_timer invalidate];
- switch (adModel.type) {
- case DYAdModelTypeLongAnimation:
- {
- [self setupView1];
- }
- break;
- case DYAdModelTypeGiftOpen:
- {
- [self setupView2];
- }
- break;
- case DYAdModelTypeGifttOpenAnimation:
- {
- [self setupView3];
- }
- break;
- case DYAdModelTypeGiftAfterOpen:
- {
- [self setupView4];
- }
- case DYAdModelTypePackRedOpen:
- {
- [self setupView5];
- }
-
- break;
-
- default:
- break;
- }
-
- }
- -(CGSize)titleBtnWight:(NSString *)titBtnW and:(UILabel *)titBtn {
- CGSize titleSize = [titBtnW boundingRectWithSize:CGSizeMake(ScreenWidth-60, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titBtn.font} context:nil].size;
-
- return titleSize;
- }
- /**去购彩*/
- - (void)gotoGoucaiBtnDeleGate:(NSNotification *)note{
-
- if (_goBlock) {
- _goBlock(note);
- }
-
- }
- // 龙
- - (void)setupView1 {
- for ( int i = 0; i < _itemsCount; i++ ) {
-
- DYAdModel *adModel = [_adDataList objectAtIndex:i];
-
-
- UILabel *titleLong = [[UILabel alloc]init];
- titleLong.font = [UIFont systemFontOfSize:25 weight:UIFontWeightMedium];
- titleLong.layer.shadowColor = [UIColor clearColor].CGColor;
- //titleLong.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
- titleLong.numberOfLines=0;
- titleLong.textColor=[UIColor whiteColor];
- [self addSubview:titleLong];
- if (adModel.content.length>0) {
- titleLong.text=[NSString stringWithFormat:@"%@",adModel.content];
- }
-
- CGFloat titleH=[self titleBtnWight:adModel.content and:titleLong].height;
- titleLong.frame=CGRectMake(30,(JX_SCREEN_HEIGHT>=812?JX_SCREEN_HEIGHT/5:JX_SCREEN_HEIGHT/5-68) , ScreenWidth-60, titleH+20);
-
-
- DYItemView*item = [[DYItemView alloc]initWithFrame:CGRectMake(100+i*ScrollWidth,JX_SCREEN_HEIGHT/6+80, JX_SCREEN_WIDTH-200, JX_SCREEN_HEIGHT/2)];
-
- item.userInteractionEnabled = YES;
- item.index = i;
- item.tag = BaseTag+item.index;
-
- LOTAnimationView *animation = [LOTAnimationView animationNamed:@"kill-dragon"];
- animation.loopAnimation = NO;
- animation.frame = CGRectMake(0, JX_SCREEN_HEIGHT>=812?64:0, ScreenWidth, ScreenHeight>=812?JX_SCREEN_HEIGHT-JX_SCREEN_TOP-64:JX_SCREEN_HEIGHT);
- [self addSubview:animation];
- __weak __typeof(self)weakSelf = self;
- [animation playWithCompletion:^(BOOL animationFinished) {
- // Do Something
- [animation removeFromSuperview];
- LOTAnimationView *animation = [LOTAnimationView animationNamed:@"dragon-idle"];
- animation.loopAnimation = YES;
- animation.frame = CGRectMake(0, JX_SCREEN_HEIGHT>=812?64:0, ScreenWidth, ScreenHeight>=812?JX_SCREEN_HEIGHT-JX_SCREEN_TOP-64:JX_SCREEN_HEIGHT);
- [weakSelf addSubview:animation];
- UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:weakSelf action:@selector(tapContentImgView:)];
- [animation addGestureRecognizer:singleTap];
- UIButton *closeBtn = [[UIButton alloc]init];
- [closeBtn setTitle:@"x" forState:UIControlStateNormal];
- closeBtn.titleLabel.font=[UIFont systemFontOfSize:20 weight:UIControlStateNormal];
- closeBtn.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.5];
- closeBtn.layer.cornerRadius=22;
- closeBtn.layer.masksToBounds=22;
- closeBtn.frame=CGRectMake(JX_SCREEN_WIDTH-60, (JX_SCREEN_HEIGHT>=812?68:34), 44, 44);
- [closeBtn addTarget:self action:@selector(tapContentImgViewXX:) forControlEvents:(UIControlEventTouchUpInside)];
- [weakSelf addSubview:closeBtn];
- [animation playWithCompletion:^(BOOL animationFinished) {
- // Do Something
- [animation removeFromSuperview];
-
- }];
- }];
-
-
- [_scrollView addSubview:item];
-
- }
- //初始化pageControl
- pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, ScreenHeight-120, ScreenWidth, 20)];
- pageControl.numberOfPages = _itemsCount;
- pageControl.currentPage = 0;
- [pageControl addTarget:self action:@selector(pageValueChange:) forControlEvents:UIControlEventValueChanged];
- pageControl.hidden = self.hiddenPageControl;
-
- [self addSubview:pageControl];
-
-
- }
- //点击文字 龙消失
- -(void)tapContentImgViewXX:(UITapGestureRecognizer *)gesture{
-
- [self removeSelfFromSuperview];
-
- }
- - (void)setupView2 {
- for ( int i = 0; i < _itemsCount; i++ ) {
- DYAdModel *adModel = [_adDataList objectAtIndex:i];
- DYItemView*item = [[DYItemView alloc]initWithFrame:CGRectMake(ScreenWidth/2-375/2+i*ScrollWidth,0, 375, 600)];
- item.userInteractionEnabled = NO;
- item.index = i;
- item.tag = BaseTag+item.index;
- item.lable.text = adModel.content;
- //NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:adModel.imgStr ofType:nil];
-
-
- // UIImageView *animatedImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT>=812?64:0, ScreenWidth, ScreenHeight>=812?JX_SCREEN_HEIGHT-JX_SCREEN_TOP-64:JX_SCREEN_HEIGHT)];
- // animatedImageView.image=[UIImage imageNamed:@"010004"];
- // [self addSubview:animatedImageView];
- // animatedImageView.userInteractionEnabled = YES;
- // self.animatedImageView=animatedImageView;
- //
- //
- // CABasicAnimation *anima = [CABasicAnimation animation];
- // anima.keyPath = @"transform.scale";
- // anima.toValue = @0.5;
- // anima.repeatCount = MAXFLOAT;
- // anima.duration = 0.3;
- // anima.autoreverses = YES;
- // [animatedImageView.layer addAnimation:anima forKey:nil];
- // self.animaaaa=anima;
-
-
- LOTAnimationView *animation = [LOTAnimationView animationNamed:@"red-packet-loop-animation"];
- animation.loopAnimation = YES;
- animation.frame = CGRectMake(0, JX_SCREEN_HEIGHT>=812?64:0, ScreenWidth, ScreenHeight>=812?JX_SCREEN_HEIGHT-JX_SCREEN_TOP-64:JX_SCREEN_HEIGHT);
- [self addSubview:animation];
- [animation playWithCompletion:^(BOOL animationFinished) {
- // Do Something
-
- }];
-
-
-
-
- UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapContentImgView:)];
- [animation addGestureRecognizer:singleTap];
- [_scrollView addSubview:item];
- // 正常显示取消按钮
- if (adModel.showCancelButton) {
- cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- cancelBtn.frame=CGRectMake(JX_SCREEN_WIDTH-60, JX_SCREEN_WIDTH/3+ (JX_SCREEN_HEIGHT>=812?0:0), 44, 44);
-
- //cancelBtn.frame = CGRectMake(ScreenWidth/2-22, ScreenHeight-70, 44, 44);
- [cancelBtn setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
- [cancelBtn addTarget:self action:@selector(removeSelfFromSuperview) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:cancelBtn];
- }
- }
-
- //初始化pageControl
- pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, ScreenHeight-120, ScreenWidth, 20)];
- pageControl.numberOfPages = _itemsCount;
- pageControl.currentPage = 0;
- [pageControl addTarget:self action:@selector(pageValueChange:) forControlEvents:UIControlEventValueChanged];
- pageControl.hidden = self.hiddenPageControl;
-
- [self addSubview:pageControl];
- }
- - (void)setupView3 {
- for ( int i = 0; i < _itemsCount; i++ ) {
- DYAdModel *adModel = [_adDataList objectAtIndex:i];
- DYItemView*item = [[DYItemView alloc]initWithFrame:CGRectMake(ScreenWidth/2-375/2+i*ScrollWidth,0, 375, 600)];
- item.userInteractionEnabled = NO;
- item.index = i;
- item.tag = BaseTag+item.index;
- item.lable.text = adModel.content;
- NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:@"准点红包2.gif" ofType:nil];
- NSData *imageData = [NSData dataWithContentsOfFile:filePath];
- if ([adModel.imgStr containsString:@".gif"]) {
- // FLAnimatedImage *animatedImage = [[FLAnimatedImage alloc] initWithAnimatedGIFData:imageData];
- // item.imageView.animatedImage = animatedImage;
- item.imageView.userInteractionEnabled = NO;
- item.userInteractionEnabled = NO;
-
- LOTAnimationView *animation = [LOTAnimationView animationNamed:@"red-packet-opened-loop-animation"];
- animation.loopAnimation = YES;
- animation.frame = CGRectMake(0, JX_SCREEN_HEIGHT>=812?64:0, ScreenWidth, ScreenHeight>=812?JX_SCREEN_HEIGHT-JX_SCREEN_TOP-64:JX_SCREEN_HEIGHT);
- [self addSubview:animation];
- [animation playWithCompletion:^(BOOL animationFinished) {
- // Do Something
-
- }];
- _animation = animation;
-
- }else {
- FLAnimatedImage *animatedImage = [[FLAnimatedImage alloc] initWithAnimatedGIFData:imageData];
- item.imageView.animatedImage = animatedImage;
- item.imageView.userInteractionEnabled = NO;
- item.userInteractionEnabled = NO;
- // item.imageView.image = [UIImage imageWithData:imageData];
- // item.imageView.userInteractionEnabled = YES;
- // item.userInteractionEnabled = YES;
- }
- UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapContentImgView:)];
- [item.imageView addGestureRecognizer:singleTap];
- [_scrollView addSubview:item];
- // 正常显示取消按钮
- if (adModel.showCancelButton) {
- cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- cancelBtn.frame = CGRectMake(ScreenWidth/2-22, ScreenHeight-70, 44, 44);
- [cancelBtn setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
- [cancelBtn addTarget:self action:@selector(removeSelfFromSuperview) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:cancelBtn];
- }
- }
- //初始化pageControl
- pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, ScreenHeight-120, ScreenWidth, 20)];
- pageControl.numberOfPages = _itemsCount;
- pageControl.currentPage = 0;
- [pageControl addTarget:self action:@selector(pageValueChange:) forControlEvents:UIControlEventValueChanged];
- pageControl.hidden = self.hiddenPageControl;
- [self addSubview:pageControl];
-
- _currentTime=4;
- _timer = [NSTimer scheduledTimerWithTimeInterval:_currentTime target:self selector:@selector(tapContentImgViewaaa:) userInfo:nil repeats:NO];
- [[NSRunLoop mainRunLoop] addTimer:_timer forMode: NSRunLoopCommonModes];
-
-
-
- }
- - (void)tapContentImgViewaaa:(NSTimer *)timer{
- _currentTime--;
- if (_currentTime<=0) {
- _timer=nil;
- [_timer invalidate];
- [self setupView5];
- }
- }
- - (void)setupView4 {
- for ( int i = 0; i < _itemsCount; i++ ) {
- DYAdModel *adModel = [_adDataList objectAtIndex:i];
- DYItemView*item = [[DYItemView alloc]initWithFrame:CGRectMake(ScreenWidth/2-250/2+i*ScrollWidth,ScrollHeight/2-100, 250, 250)];
- item.userInteractionEnabled = YES;
- item.index = i;
- item.tag = BaseTag+item.index;
- // item.lable.text = adModel.content;
- NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:adModel.imgStr ofType:nil];
- NSData *imageData = [NSData dataWithContentsOfFile:filePath];
- if ([adModel.imgStr containsString:@".gif"]) {
- FLAnimatedImage *animatedImage = [[FLAnimatedImage alloc] initWithAnimatedGIFData:imageData];
- item.imageView.animatedImage = animatedImage;
- item.imageView.userInteractionEnabled = YES;
- item.userInteractionEnabled = YES;
- }else {
- item.imageView.image = [UIImage imageWithData:imageData];
- item.imageView.userInteractionEnabled = YES;
- item.userInteractionEnabled = YES;
- }
- [_scrollView addSubview:item];
-
- // containerView
- UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(ScreenWidth/2-250/2+i*ScrollWidth,ScrollHeight/2-100, 250, 250)];
- containerView.backgroundColor = [UIColor clearColor];
- [_scrollView addSubview:containerView];
- // 添加动画边框
- NSString *filePath1 = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:@"光效" ofType:@"gif"];
- NSData *imageData1 = [NSData dataWithContentsOfFile:filePath1];
- FLAnimatedImage *animatedImage = [[FLAnimatedImage alloc] initWithAnimatedGIFData:imageData1];
- FLAnimatedImageView *animatedImageView = [[FLAnimatedImageView alloc]initWithFrame:CGRectMake(0, 10, containerView.frame.size.width, containerView.frame.size.width)];
- animatedImageView.contentMode = UIViewContentModeScaleToFill;
- animatedImageView.animatedImage = animatedImage;
- animatedImageView.backgroundColor = [UIColor clearColor];
- animatedImageView.layer.cornerRadius = 22;
- animatedImageView.layer.masksToBounds = YES;
- [containerView addSubview:animatedImageView];
-
- // 标题获得奖励 往下30
- UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, containerView.frame.size.width, 30)];
- label1.font = [UIFont systemFontOfSize:14];
- label1.text = adModel.success ? @"获得奖励": @"很遗憾";
- label1.textAlignment = NSTextAlignmentCenter;
- label1.textColor = [UIColor whiteColor];
- [containerView addSubview:label1];
- // 恭喜您获得
- UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, containerView.frame.size.width, 30)];
- label2.font = [UIFont systemFontOfSize:12];
- label2.text = adModel.success ? @"恭喜您获得": @"下次加油哦💪💪💪";
- label2.textAlignment = NSTextAlignmentCenter;
- label2.textColor = [UIColor whiteColor];
- [containerView addSubview:label2];
- // 奖品图标
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(95, 88, 60, 60)];
- if (adModel.success) {
- [imageView sd_setImageWithURL:[NSURL URLWithString:adModel.linkUrl] placeholderImage:[UIImage imageNamed:@"gift_default"]];
- }else {
- imageView.image = [UIImage imageNamed:@"face_cry"];
- }
-
- [containerView addSubview:imageView];
- // 奖品名称
- UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, containerView.frame.size.width, 30)];
- label3.font = [UIFont systemFontOfSize:12];
- label3.text = adModel.content;
- label3.textAlignment = NSTextAlignmentCenter;
- label3.textColor = [UIColor whiteColor];
- [containerView addSubview:label3];
- // 确定按钮
- UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(0, 205, containerView.frame.size.width, 30)];
- label4.font = [UIFont systemFontOfSize:13];
- label4.text = @"确定";
- label4.textAlignment = NSTextAlignmentCenter;
- label4.textColor = [UIColor whiteColor];
- [containerView addSubview:label4];
- UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapContentImgView:)];
- [label4 addGestureRecognizer:singleTap];
- label4.userInteractionEnabled = YES;
-
- // 正常显示取消按钮
- if (adModel.showCancelButton) {
- cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- cancelBtn.frame=CGRectMake(JX_SCREEN_WIDTH-60, JX_SCREEN_WIDTH/3+ (JX_SCREEN_HEIGHT>=812?0:0), 44, 44);
- // cancelBtn.frame = CGRectMake(ScreenWidth/2-22, ScreenHeight-80, 44, 44);
- [cancelBtn setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
- [cancelBtn addTarget:self action:@selector(removeSelfFromSuperview) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:cancelBtn];
- }
- }
-
- //初始化pageControl
- pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, ScreenHeight-120, ScreenWidth, 20)];
- pageControl.numberOfPages = _itemsCount;
- pageControl.currentPage = 0;
- [pageControl addTarget:self action:@selector(pageValueChange:) forControlEvents:UIControlEventValueChanged];
- pageControl.hidden = self.hiddenPageControl;
-
- [self addSubview:pageControl];
- }
- - (void)setupView5 {
- for ( int i = 0; i < _itemsCount; i++ ) {
- DYAdModel *adModel = [_adDataList objectAtIndex:i];
- DYItemView*item = [[DYItemView alloc]initWithFrame:CGRectMake(ScreenWidth/2-375/2+i*ScrollWidth,0, 375, 600)];
- item.userInteractionEnabled = NO;
- item.index = i;
- item.tag = BaseTag+item.index;
-
-
- // UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapContentImgView:)];
- // [item.imageView addGestureRecognizer:singleTap];
- // [_scrollView addSubview:item];
- // 正常显示取消按钮
-
- cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- cancelBtn.frame = CGRectMake(ScreenWidth-100, JX_SCREEN_HEIGHT/6, 44, 44);
- [cancelBtn setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
- [cancelBtn addTarget:self action:@selector(removeSelfFromSuperview) forControlEvents:UIControlEventTouchUpInside];
-
- if ([adModel.imgStr isEqualToString:@"红包领取失败"]) {
- LOTAnimationView *animation = [LOTAnimationView animationNamed:@"red-packet-opened-loop-animation"];
- animation.loopAnimation = YES;
- animation.frame = CGRectMake(0, JX_SCREEN_HEIGHT>=812?64:0, ScreenWidth, ScreenHeight>=812?JX_SCREEN_HEIGHT-JX_SCREEN_TOP-64:JX_SCREEN_HEIGHT);
- [self addSubview:animation];
- [animation playWithCompletion:^(BOOL animationFinished) {
- // Do Something
-
- }];
-
- [self addSubview:cancelBtn];
- UILabel *titleLong = [[UILabel alloc]init];
-
- titleLong.textColor=[UIColor whiteColor];
- titleLong.userInteractionEnabled=YES;
- titleLong.textAlignment=NSTextAlignmentCenter;
- titleLong.numberOfLines = 0;
- [animation addSubview:titleLong];
- if ([adModel.imgStr isEqualToString:@"红包领取失败"]) {
- titleLong.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
- titleLong.text = [NSString stringWithFormat:@"很遗憾\n红包已被领完"];
- }else {
- titleLong.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
- titleLong.text = [NSString stringWithFormat:@"中奖了\n%@元",adModel.content];
- }
-
- [titleLong mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(animation.mas_centerX);
- make.centerY.mas_equalTo(animation.mas_centerY).mas_offset(-5);;
- }];
- }else {
- LOTAnimationView *animation = [LOTAnimationView animationNamed:@"red-packet-opened-loop-animation"];
- animation.loopAnimation = YES;
- animation.frame = CGRectMake(0, JX_SCREEN_HEIGHT>=812?64:0, ScreenWidth, ScreenHeight>=812?JX_SCREEN_HEIGHT-JX_SCREEN_TOP-64:JX_SCREEN_HEIGHT);
- [self addSubview:animation];
- [animation playWithCompletion:^(BOOL animationFinished) {
- // Do Something
-
- }];
- UITapGestureRecognizer *singleTapBt = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapContentImgViewXX:)];
- [animation addGestureRecognizer:singleTapBt];
- [self addSubview:cancelBtn];
- UILabel *titleLong = [[UILabel alloc]init];
-
- titleLong.textColor=[UIColor whiteColor];
- titleLong.userInteractionEnabled=YES;
- titleLong.textAlignment=NSTextAlignmentCenter;
- titleLong.numberOfLines = 0;
- [animation addSubview:titleLong];
- if ([adModel.imgStr isEqualToString:@"红包领取失败"]) {
- titleLong.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
- titleLong.text = [NSString stringWithFormat:@"很遗憾\n红包已被领完"];
- }else {
- titleLong.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
- titleLong.text = [NSString stringWithFormat:@"中奖了\n%@元",adModel.content];
- }
-
- [titleLong mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(animation.mas_centerX);
- make.centerY.mas_equalTo(animation.mas_centerY).mas_offset(-5);;
- }];
- }
-
- }
- //初始化pageControl
- pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, ScreenHeight-120, ScreenWidth, 20)];
- pageControl.numberOfPages = _itemsCount;
- pageControl.currentPage = 0;
- [pageControl addTarget:self action:@selector(pageValueChange:) forControlEvents:UIControlEventValueChanged];
- pageControl.hidden = self.hiddenPageControl;
-
- [self addSubview:pageControl];
- }
- - (void)tapContentImgViewxx{
-
- [self removeFromSuperview];
- }
- +(void)dissmissUI{
-
- DYAdAlertView *dissVIew=[DYAdAlertView new];
-
- [dissVIew removeSelfFromSuperview];
- }
- -(void)dissmissDYAdAlertView{
-
- [self removeFromSuperview];
- }
- //点击文字 龙消失
- -(void)tapContentImgView:(UITapGestureRecognizer *)gesture{
- // UIView *imageView = gesture.view;
- // NSInteger itemTag = (long)imageView.tag-BaseTag;
-
-
- if ([self.delegate respondsToSelector:@selector(clickAlertViewAtIndex:)]){
- [self.delegate clickAlertViewAtIndex:0];
- [self removeSelfFromSuperview];
- // self.animaaaa=anima;
- //animatedImageView
-
-
- }
- }
- -(void)pageValueChange:(UIPageControl*)page{
-
- [UIView animateWithDuration:.35 animations:^{
- _scrollView.contentOffset = CGPointMake(page.currentPage*ScreenWidth, 0);
- }];
- }
- #pragma mark - UIScrollViewDelegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
-
- NSInteger index = scrollView.contentOffset.x/ScreenWidth;
- pageControl.currentPage = index;
- }
- @end
- /*********D*********Y**********分**********割**********线************/
- //自定义中间主界面
- @implementation DYItemView
- -(id)initWithFrame:(CGRect)frame{
-
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor clearColor];
-
- [self setSubViews];
- }
- return self;
- }
- -(void)setSubViews{
- self.userInteractionEnabled = YES;
- self.layer.masksToBounds = YES;
- self.layer.cornerRadius = 5;
- self.layer.shadowOpacity = .2;
- self.layer.shadowOffset = CGSizeMake(0, 2.5);
- self.layer.shadowColor = [UIColor clearColor].CGColor;
-
- [self addSubview:self.imageView];
- [self addSubview:self.lable];
-
- }
- -(FLAnimatedImageView *)imageView{
- if (!_imageView) {
- _imageView = [[FLAnimatedImageView alloc]initWithFrame:self.bounds];
- _imageView.backgroundColor = [UIColor clearColor];
- _imageView.userInteractionEnabled = YES;
- _imageView.layer.masksToBounds = YES;
- }
- return _imageView;
- }
- -(UILabel *)lable {
- if (!_lable) {
- _lable = [[UILabel alloc] init];
- _lable.font = [UIFont systemFontOfSize:25];
- _lable.textColor = [UIColor whiteColor];
- _lable.userInteractionEnabled=YES;
- //_lable.backgroundColor=[UIColor redColor];
- _lable.frame = CGRectMake(0, 0, ScreenWidth, 10);
- //[_lable setCenter:CGPointMake(0, 50)];
- // _lable.text = @"哈哈哈啊哈哈\n哈哈 哈 哈哈\n 点击屠龙";
- _lable.numberOfLines = 0;
- _lable.textAlignment = NSTextAlignmentCenter;
- // [_lable sizeToFit];
-
- }
- return _lable;
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- [self endEditing:YES];
- }
- @end
|