// // MOChooseTimeAlertView.m // MiMoLive // // Created by SuperC on 2023/12/13. // #import "MOChooseTimeAlertView.h" @interface MOChooseTimeAlertView () @property (weak, nonatomic) IBOutlet UIView *bgView; @property (weak, nonatomic) IBOutlet UILabel *titleLab; @property (weak, nonatomic) IBOutlet UILabel *topTipLab; @property (weak, nonatomic) IBOutlet UILabel *bottomTipLab; @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property (weak, nonatomic) IBOutlet UIButton *cancelBtn; @property (weak, nonatomic) IBOutlet UIButton *confirmBtn; @end @implementation MOChooseTimeAlertView + (instancetype)moChooseTimeAlertView{ return [[[NSBundle mainBundle] loadNibNamed:@"MOChooseTimeAlertView" owner:self options:nil] firstObject]; } - (void)awakeFromNib{ [super awakeFromNib]; self.titleLab.text = NSLocalString(@"mimo_room_confirm_title"); self.bgView.layer.cornerRadius = 16.0; self.bgView.layer.masksToBounds = YES; self.cancelBtn.layer.cornerRadius = 50.0 / 2.0; self.cancelBtn.layer.masksToBounds = YES; self.cancelBtn.layer.borderColor = [MOTools colorWithHexString:@"#B7B6B6" alpha:1.0].CGColor; self.cancelBtn.layer.borderWidth = 1.0; [self.cancelBtn setTitle:NSLocalString(@"mimo_Cancel") forState:UIControlStateNormal]; CGFloat imgWidth = (SCREENWIDTH - 10.0 * 2.0 - 17.0 * 2.0 - 15.0) / 2.0; self.confirmBtn.layer.cornerRadius = 50.0 / 2.0; self.confirmBtn.layer.masksToBounds = YES; NSArray *colorArr = @[kBaseBtnBgColor,kBaseBtnBgColor]; UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, imgWidth, 50.0) Colors:colorArr GradientType:0]; [self.confirmBtn setBackgroundImage:image forState:UIControlStateNormal]; [self.confirmBtn setTitle:NSLocalString(@"mimo_TipConfirm") forState:UIControlStateNormal]; UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init]; CGFloat width = (SCREENWIDTH - 10.0 * 2 - 15.0 * 2 - 9.0 * 2) / 3.0; CGFloat height = 35.0; flow.itemSize = CGSizeMake(width, height); flow.minimumLineSpacing = 10.0;//行间距 flow.minimumInteritemSpacing = 8.0;//列间距 flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); [self.collectionView setCollectionViewLayout:flow]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.backgroundColor = [MOTools colorWithHexString:@"#F9F9F9" alpha:1.0]; [self.collectionView registerClass:[MOChooseTimeCell class] forCellWithReuseIdentifier:MOChooseTimeCell_ID]; self.selectIndex = 0; } #pragma mark - Set - (void)setDataArr:(NSArray *)dataArr{ _dataArr = dataArr; [self.collectionView reloadData]; } - (void)setTitleText:(NSString *)titleText{ _titleText = titleText; self.titleLab.text = titleText; } - (void)setTopTipText:(NSString *)topTipText{ _topTipText = topTipText; self.topTipLab.text = topTipText; } - (void)setBottomTipText:(NSString *)bottomTipText{ _bottomTipText = bottomTipText; if(bottomTipText.length == 0){ self.bottomTipLab.hidden = YES; } else{ self.bottomTipLab.hidden = NO; self.bottomTipLab.text = bottomTipText; } } #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{ NSString *cellStr = self.dataArr[indexPath.row]; MOChooseTimeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOChooseTimeCell_ID forIndexPath:indexPath]; cell.titleLab.text = cellStr; if(self.selectIndex == indexPath.row){ cell.isChoose = YES; } else{ cell.isChoose = NO; } return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [collectionView deselectItemAtIndexPath:indexPath animated:YES]; if(self.selectIndex + 1 <= self.dataArr.count){ self.selectIndex = indexPath.row; [self.collectionView reloadData]; } } #pragma mark - Show - (IBAction)dismissBtnClick:(id)sender { [self dismissChooseTimeAlertView]; } - (IBAction)cancelBtnClick:(id)sender { [self dismissChooseTimeAlertView]; } - (IBAction)confirmBtnClick:(id)sender { self.confirmBtnBlock ? self.confirmBtnBlock(self.selectIndex) : nil; [self dismissChooseTimeAlertView]; } - (void)showChooseTimeAlertView//界面显示动画 { 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)dismissChooseTimeAlertView//取消掉键盘 { [UIView animateWithDuration:0.2 animations:^ { self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3); self.bgView.alpha = 0; } completion:^(BOOL finished) { if (finished) { [self.bgView removeFromSuperview]; [self removeFromSuperview]; } }]; } @end