// // 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 @interface DYAdAlertView() { 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]; 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:)]; [self 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:)]; [self 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:)]; // [self addGestureRecognizer:singleTap]; // [_scrollView addSubview:item]; // 正常显示取消按钮 cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; cancelBtn.frame = CGRectMake(ScreenWidth-100, 88, 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 *)touches withEvent:(UIEvent *)event{ [self endEditing:YES]; } @end