| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- //
- // MOSignInAlertView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/5/31.
- //
- #import "MOSignInAlertView.h"
- #import "MOSignInGiftCell.h"
- @interface MOSignInAlertView ()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property (weak, nonatomic) IBOutlet UIView *bgView;
- @property (weak, nonatomic) IBOutlet UILabel *titleLab;
- @property (weak, nonatomic) IBOutlet UILabel *dayNumLab;
- @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewWidth;
- @property (weak, nonatomic) IBOutlet UILabel *tipLab;
- @property (weak, nonatomic) IBOutlet UIButton *signInBtn;
- @property (weak, nonatomic) IBOutlet UIButton *closeBtn;
- /** 数据源 */
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @end
- @implementation MOSignInAlertView
- + (instancetype)moSignInAlertView{
- return [[[NSBundle mainBundle] loadNibNamed:@"MOSignInAlertView" owner:self options:nil] firstObject];
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
-
- [self.signInBtn setBackgroundColor:kBaseBtnBgColor];
- self.signInBtn.layer.cornerRadius = 36.0 / 2.0;
- self.signInBtn.layer.masksToBounds = YES;
-
- self.titleLab.textColor = kBaseBtnBgColor;
-
- UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
- flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- CGFloat width = 66.0;
- CGFloat height = 74.0;
-
- flow.itemSize = CGSizeMake(width, height);
- flow.minimumLineSpacing = 5.0;//行间距
- flow.minimumInteritemSpacing = 0.0;//列间距
- [self.collectionView setCollectionViewLayout:flow];
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.backgroundColor = [UIColor clearColor];
- [self.collectionView registerNib:[UINib nibWithNibName:@"MOSignInGiftCell" bundle:nil] forCellWithReuseIdentifier:MOSignInGiftCell_ID];
-
- self.titleLab.text = NSLocalString(@"mimo_sign_in_title");
- self.dayNumLab.text = [NSString stringWithFormat:NSLocalString(@"mimo_sign_in_for_day"),0];
- self.tipLab.text = NSLocalString(@"mimo_sign_in_tip_two");
- [self.signInBtn setTitle:NSLocalString(@"mimo_sign_in_title") forState:UIControlStateNormal];
-
- [self.signInBtn setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
- self.tipLab.font = [MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr];
- self.dayNumLab.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];
- self.titleLab.font = [MOTextTools getTheFontWithSize:24.0 AndFontName:kNormalContentFontStr];
- }
- - (IBAction)closeBtnClick:(id)sender {
- [self dismissSignInAlertView];
- }
- - (IBAction)signInBtnClick:(id)sender {
-
- if(self.isGet){
- //已签到
- self.toTaskWebBlock ? self.toTaskWebBlock() : nil;
- [self dismissSignInAlertView];
- }
- else
- {
- //未签到
- [self toSignInAction];
- }
- }
- - (void)toSignInAction{
- WEAKSELF
- [kHttpManager toSubmitTheSignTaskAboutSignWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- weakSelf.isGet = YES;
- MOSignBaseData *model = [MOSignBaseData modelObjectWithDictionary:data[@"data"]];
-
- weakSelf.baseData.continuous = model.continuous;
- weakSelf.baseData.signPrizes = model.signPrizes;
- [weakSelf updataAllUIWithProperty];
-
- //设置签到时间
- [MOTools setTimeOfShowSignDevice:[NSDate date]];
- }
- else{
- MOLogV(@"toGetTheSignTaskInfoWithParams 接口报错了");
- kShowNetError(data)
- }
- }];
- }
- #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.dataArr.count;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- MOSignPrizes *model = self.dataArr[indexPath.row];
- MOSignInGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOSignInGiftCell_ID forIndexPath:indexPath];
- cell.isGet = self.isGet;
- cell.cellModel = model;
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
- }
- - (NSMutableArray *)dataArr{
- if(!_dataArr){
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (void)showSignInAlertView//界面显示动画
- {
-
- UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
- [keyWindow addSubview:self];
- self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
-
- //动画效果
- self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
- self.bgView.alpha = 0;
- [UIView animateWithDuration:0.2 animations:^
- {
- self.bgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
- self.bgView.alpha = 1;
- } completion:^(BOOL finished)
- {
- }];
- }
- - (void)dismissSignInAlertView
- {
- [UIView animateWithDuration:0.2 animations:^
- {
- self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
- self.bgView.alpha = 0;
- } completion:^(BOOL finished)
- {
- if (finished)
- {
- [self removeFromSuperview];
- }
- }];
- }
- - (void)setBaseData:(MOSignBaseData *)baseData{
- _baseData = baseData;
-
- [self updataAllUIWithProperty];
- }
- - (void)updataAllUIWithProperty{
- self.dataArr = [self.baseData.signPrizes mutableCopy];
-
- CGFloat theMaxWidth = 296.0 - 25.0 * 2.0;
- CGFloat theNeedWidth = self.dataArr.count * (66.0 + 5.0);
- if(theNeedWidth > theMaxWidth){
- theNeedWidth = theMaxWidth;
- }
-
- self.collectionViewWidth.constant = theNeedWidth;
- [self.collectionView reloadData];
-
- NSString *signNumDayStr = [NSString stringWithFormat:NSLocalString(@"mimo_sign_in_for_day"),self.baseData.continuous];
-
- NSMutableAttributedString *plainText = [self colorfulStringWith:signNumDayStr];
- self.dayNumLab.attributedText = plainText;
-
- if(self.isGet){
- [self.signInBtn setTitle:NSLocalString(@"mimo_sign_in_more_btn") forState:UIControlStateNormal];
- }
- else{
- [self.signInBtn setTitle:NSLocalString(@"mimo_sign_in_title") forState:UIControlStateNormal];
- }
- }
- - (NSMutableAttributedString *)colorfulStringWith:(NSString *)contentStr{
-
- NSString *numStr = [NSString stringWithFormat:@"%.f",self.baseData.continuous];
-
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSFontAttributeName:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr],NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#282828" alpha:1.0]}];
-
- NSRange redRange = [contentStr rangeOfString:numStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:kBaseBtnBgColor range:redRange];
- }
-
- return attributedString;
- }
- @end
|