123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- //
- // YOUPAILZLiveGiftView.m
- // TIANYAN
- //
- // Created by CY on 2021/5/25.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZLiveGiftView.h"
- @interface YOUPAILZLiveGiftView ()
- @property (nonatomic, weak)UILabel *youpaipcountL;
- @property (nonatomic, strong) NSTimer *youpaiptimer;
- @property (nonatomic, assign) NSInteger youpaiptimerCount;
- @property (nonatomic, strong,readwrite) YOUPAILZLiveGIftModel *youpaipgiftModel;
- @end
- @implementation YOUPAILZLiveGiftView
- + (instancetype)youpaifgiftViewWithModel:(YOUPAILZLiveGIftModel *)model{
- return [[self alloc] initWithModel:model];
- }
- - (instancetype)initWithModel:(YOUPAILZLiveGIftModel *)model{
- if (self = [super init]) {
- _youpaipgiftModel = model;
- [self youpaifinitUI];
- }
- return self;
- }
- - (void)youpaifinitUI{
- self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
- self.layer.cornerRadius = 21.0f;
-
- UIImageView *youpaipavatarImgV = [[UIImageView alloc] init];
- youpaipavatarImgV.layer.cornerRadius = 17.0f;
- youpaipavatarImgV.clipsToBounds = YES;
- [youpaipavatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipgiftModel.youpaipavatar]];
- [self addSubview:youpaipavatarImgV];
- [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.offset(4.0f);
- make.bottom.offset(-4.0f);
- make.width.offset(34.0f);
- }];
-
- UIImageView *giftImgV = [[UIImageView alloc] init];
- [giftImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipgiftModel.youpaipgiftImage]];
- [self addSubview:giftImgV];
- [giftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.offset(4.0f);
- make.bottom.right.offset(-4.0f);
- make.width.offset(34.0f);
- }];
-
- UILabel *youpaipnicknameL = [[UILabel alloc] init];
- youpaipnicknameL.font = LCFont(14.0f);
- youpaipnicknameL.textColor = [UIColor whiteColor];
- youpaipnicknameL.text = self.youpaipgiftModel.youpaipnickName;
- youpaipnicknameL.preferredMaxLayoutWidth = 124.0f;
- [self addSubview:youpaipnicknameL];
- [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.mas_centerY);
- make.left.equalTo(youpaipavatarImgV.mas_right).offset(5.0f);
- make.right.equalTo(giftImgV.mas_left).offset(-5.0f);
- }];
-
- UILabel *giftDescL = [[UILabel alloc] init];
- giftDescL.font = LCFont(14.0f);
- giftDescL.textColor = HexColorFromRGB(0xFFF3A7);
- giftDescL.text = self.youpaipgiftModel.youpaipgiftDesc;
- giftDescL.preferredMaxLayoutWidth = 124.0f;
- [self addSubview:giftDescL];
- [giftDescL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.mas_centerY);
- make.left.equalTo(youpaipavatarImgV.mas_right).offset(5.0f);
- make.right.equalTo(giftImgV.mas_left).offset(-5.0f);
- }];
-
- UILabel *youpaipcountL = [[UILabel alloc] init];
- youpaipcountL.font = LCBoldFont(30.0f);
- youpaipcountL.textColor = [UIColor whiteColor];
- youpaipcountL.text = [NSString stringWithFormat:@"x %@",@(self.youpaipgiftModel.youpaipgiftCount)];
- [self addSubview:youpaipcountL];
- self.youpaipcountL = youpaipcountL;
- [youpaipcountL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.equalTo(self);
- make.left.equalTo(self.mas_right).offset(4.0f);
- }];
- }
- - (void)youpaifshowAnimation{
- [self youpaifstartTimer];
- if (self != nil && self.superview != nil) {
- [self.superview setNeedsUpdateConstraints];
- [self mas_updateConstraints:^(MASConstraintMaker *make) {
- make.left.offset(4.0f);
- }];
- }
- [UIView animateWithDuration:0.25f animations:^{
- [self.superview layoutIfNeeded];
- }];
-
- }
- - (void)youpaifhideAnimation{
- if (self != nil && self.superview != nil) {
- [self.superview setNeedsUpdateConstraints];
- [self mas_updateConstraints:^(MASConstraintMaker *make) {
- make.left.offset(-200.0f);
- }];
- }
- [UIView animateWithDuration:0.25f animations:^{
- [self.superview layoutIfNeeded];
- } completion:^(BOOL finished) {
-
- if (finished && [self.delegate respondsToSelector:@selector(youpaifanimatiomFinishWithView:)]) {
- [self.delegate youpaifanimatiomFinishWithView:self];
- }
- }];
-
- }
- - (void)youpaifupdateGiftCount:(NSInteger)count{
- [self youpaifstopTimer];
- self.youpaipgiftModel.youpaipgiftCount += count;
- self.youpaipcountL.text = [NSString stringWithFormat:@"x %@",@(self.youpaipgiftModel.youpaipgiftCount)];
- [self youpaifstartTimer];
- }
- - (void)youpaifstartTimer{
- self.youpaiptimerCount = 2;
- self.youpaiptimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(youpaifcountDown) userInfo:nil repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:self.youpaiptimer forMode:NSRunLoopCommonModes];
- }
- - (void)youpaifstopTimer{
- [self.youpaiptimer invalidate];
- self.youpaiptimer = nil;
- }
- - (void)youpaifcountDown{
- self.youpaiptimerCount --;
- if (self.youpaiptimerCount <= 0) {
- [self youpaifstopTimer];
- [self youpaifhideAnimation];
- }
- }
- @end
|