123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- //
- // XYHotGiveRewardSheetViewController.m
- // Timi
- //
- // Created by 翟玉磊 on 2021/11/16.
- //
- #import "XYHotGiveRewardSheetViewController.h"
- #import "XYHotGiveRewardSheetViewModel.h"
- #import "XYHotGiveRewardUserListTableViewCell.h"
- #import "XYHotGiveRewardUserListModel.h"
- #import "XYUserDynamicListCellModel.h"
- typedef void(^SelectedDidBlock)(BOOL success, XYUserDynamicListCellModel *dynamicModel);
- @interface XYHotGiveRewardSheetViewController ()<UITableViewDelegate, UITableViewDataSource>
- @property (nonatomic, strong) XYHotGiveRewardSheetViewModel *viewModel;
- @property (nonatomic, readwrite, strong) UIView *bgView;
- @property (nonatomic, readwrite, strong) UIView *infoView;
- @property (nonatomic, readwrite, strong) UIView *titleView;
- @property (nonatomic, readwrite, strong) UILabel *titleLabel;
- @property (nonatomic, readwrite, strong) UIButton *closeButton;
- @property (nonatomic, readwrite, strong) UIView *sendGiftView;
- @property (nonatomic, readwrite, strong) UIButton *sendGiftButton;
- @property (nonatomic, readwrite, strong) XYUserDynamicListCellModel *dynamicModel;
- @property (nonatomic, readwrite, copy) SelectedDidBlock selectedDidBlock;
- @end
- @implementation XYHotGiveRewardSheetViewController
- #pragma mark — Public
- + (instancetype)showWithDynamicModel:(XYUserDynamicListCellModel *)dynamicModel parentController:(UIViewController *)parentController completeBlock:(void(^)(BOOL success, XYUserDynamicListCellModel *dynamicModel))block {
-
- XYHotGiveRewardSheetViewController *alertVC = XYHotGiveRewardSheetViewController.new;
- alertVC.dynamicModel = dynamicModel;
- alertVC.selectedDidBlock = block;
- alertVC.view.hidden = YES;
- // 添加控制器
- [parentController addChildViewController:alertVC];
- [parentController.view addSubview:alertVC.view];
- [alertVC didMoveToParentViewController:parentController];
-
- return alertVC;
- }
- - (void)show {
-
- self.view.hidden = NO;
- [UIView animateWithDuration:.3 animations:^{
- self.infoView.frame = CGRectMake(self.infoView.f_x, SCREEN_HEIGHT - self.infoView.f_heigh, self.infoView.f_width, self.infoView.f_heigh);
- } completion:^(BOOL finished) {
-
- }];
- }
- - (void)dismiss {
-
- [UIView animateWithDuration:.3 animations:^{
- self.infoView.frame = CGRectMake(self.infoView.f_x, SCREEN_HEIGHT, self.infoView.f_width, self.infoView.f_heigh);
- } completion:^(BOOL finished) {
-
- [self willMoveToParentViewController:nil];
- [self.view removeFromSuperview];
- [self removeFromParentViewController];
- }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.view.backgroundColor = Color_Clear;
-
- /// 设置
- [self _setup];
-
- /// 设置导航栏
- [self _setupNavigationItem];
-
- /// 设置子控件
- [self _setupSubViews];
-
- /// 布局子空间
- [self _makeSubViewsConstraints];
-
- [self tableViewDidTriggerHeaderRefresh];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self show];
- });
- }
- #pragma mark - Override
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(0, 0, 0, 0);
- }
- - (void)bindViewModel {
- self.viewModel = XYHotGiveRewardSheetViewModel.new;
- self.viewModel.dynamicModel = self.dynamicModel;
- }
- - (void)tableViewDidTriggerHeaderRefresh {
- self.viewModel.pullDown = YES;
- [self.viewModel loadData:^(id _Nullable responseModel) {
-
- // [self updateViewFrame];
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeNoSkillCertification emptyInfo:@"" errorInfo:@"" offsetTop:DefaultOffsetTop-100.0f hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
- } failure:^(ZYLNetworkError * _Nullable error) {
- [self tableViewDidFinishTriggerHeader:YES reload:NO];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:DefaultOffsetTop hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
- [self dismiss];
- }];
- }
- - (void)updateViewFrame {
- CGFloat infoHeight = 44.0f;
- infoHeight += (self.viewModel.dataSource.count * 48.0f);
- if ([self.dynamicModel.userId isEqualToString:[XYUserInfoManager nowUser].userId]) {
- // 自己
- infoHeight += 0.0f;
- }else {
- // 别人
- infoHeight += 64.0f;
- }
- infoHeight += HOME_INDICATOR_HEIGHT;
-
- // infoView最大高度不能超过半屏
- infoHeight = MIN(infoHeight, SCREEN_HEIGHT/2);
-
- self.infoView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, infoHeight);
- }
- #pragma mark - 事件处理Or辅助方法
- - (void)closeButtonAction:(id)sender {
- if (self.selectedDidBlock) {
- self.selectedDidBlock(NO, self.dynamicModel);
- }
- [self dismiss];
- }
- - (void)sendGiftButtonAction:(id)sender {
- if (self.selectedDidBlock) {
- self.selectedDidBlock(YES, self.dynamicModel);
- }
- [self dismiss];
- }
- #pragma mark - UITableViewDelegate
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.viewModel.dataSource.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 48.0f;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- XYHotGiveRewardUserListTableViewCell *cell = [XYHotGiveRewardUserListTableViewCell cellWithTableView:tableView];
- [cell configureModel:self.viewModel.dataSource[indexPath.row]];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- // 关闭
- [self closeButtonAction:nil];
-
- XYHotGiveRewardUserListModel *model = self.viewModel.dataSource[indexPath.row];
- XYUserMainViewController *controller = XYUserMainViewController.new;
- controller.targetId = [model.userId copy];
- [ApplicationDelegate.getCurrentController.navigationController pushViewController:controller animated:YES];
- }
- #pragma mark - 初始化
- - (void)_setup{
- }
- #pragma mark - 设置导航栏
- - (void)_setupNavigationItem{
-
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews{
-
- [self.view addSubview:self.bgView];
- [self.view addSubview:self.infoView];
-
- [self.infoView addSubview:self.titleView];
- [self.titleView addSubview:self.titleLabel];
- [self.titleView addSubview:self.closeButton];
-
- [self.infoView addSubview:self.tableView];
-
- [self.infoView addSubview:self.sendGiftView];
- [self.sendGiftView addSubview:self.sendGiftButton];
-
- [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.equalTo(self.infoView);
- make.height.equalTo(@44.0f);
- }];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.titleView).offset(16.0f);
- make.centerY.equalTo(self.titleView);
- }];
- [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.titleView).offset(-10.0f);
- make.centerY.equalTo(self.titleView);
- make.width.height.equalTo(@44.0f);
- }];
-
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.infoView);
- make.top.equalTo(self.titleView.mas_bottom);
- make.bottom.equalTo(self.sendGiftView.mas_top);
- }];
-
- if ([self.dynamicModel.userId isEqualToString:[XYUserInfoManager nowUser].userId]) {
- // 自己则不显示打赏按钮
- [self.sendGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.equalTo(self.infoView);
- make.height.equalTo(@(HOME_INDICATOR_HEIGHT));
- }];
- self.sendGiftButton.hidden = YES;
-
- }else {
- [self.sendGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.equalTo(self.infoView);
- make.height.equalTo(@(64.0f + HOME_INDICATOR_HEIGHT));
- }];
- [self.sendGiftButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.sendGiftView).offset(16.0f);
- make.right.equalTo(self.sendGiftView).offset(-16.0f);
- make.top.equalTo(self.sendGiftView).offset(8.0f);
- make.height.equalTo(@48.0f);
- }];
-
- self.sendGiftView.size = CGSizeMake(SCREEN_WIDTH, 64.0f + HOME_INDICATOR_HEIGHT);
-
- self.sendGiftButton.hidden = NO;
- [self.sendGiftButton addViewBorder:Color_Clear redian:48/2];
- }
-
- [self.infoView addViewBorderWithCorners:UIRectCornerTopLeft|UIRectCornerTopRight color:Color_Clear redian:16];
-
- [self.sendGiftView addViewShadowWithShadowColor:ColorFromHexStringWithAlpha(@"#000000", 0.1f) shadowOffset:CGSizeMake(0, 0) shadowOpacity:1 shadowRadius:4 cornerRadius:0];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
-
- }
- #pragma mark - Setter & Getter
- - (UIView *)bgView {
- if (_bgView == nil) {
- _bgView = [[UIView alloc] initWithFrame:SCREEN_BOUNDS];
- _bgView.backgroundColor = ColorFromHexStringWithAlpha(@"#1D1C1F", 0.35f);
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeButtonAction:)];
- [_bgView addGestureRecognizer:tap];
- }
- return _bgView;
- }
- - (UIView *)infoView {
- if (_infoView == nil) {
- _infoView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT/2)];
- _infoView.backgroundColor = Color_White;
- }
- return _infoView;
- }
- - (UIView *)titleView {
- if (_titleView == nil) {
- _titleView = [[UIView alloc] init];
- }
- return _titleView;
- }
- - (UILabel *)titleLabel {
- if (_titleLabel == nil) {
- _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_S(18)];
- _titleLabel.text = @"热门打赏";
- }
- return _titleLabel;
- }
- - (UIButton *)closeButton {
- if (!_closeButton) {
- _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_closeButton setImage:ImageNamed(@"icon_closex") forState:UIControlStateNormal];
- [_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeButton;
- }
- - (UIView *)sendGiftView {
- if (!_sendGiftView) {
- _sendGiftView = [[UIView alloc] init];
- _sendGiftView.backgroundColor = Color_White;
- }
- return _sendGiftView;
- }
- - (UIButton *)sendGiftButton {
- if (!_sendGiftButton) {
- _sendGiftButton = [UIButton createButtonTextColor:Color_White textFont:Font(16)];
- [_sendGiftButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[ColorFromHexString(@"#5D26FF"), ColorFromHexString(@"#8359FF")] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake((SCREEN_WIDTH - 16.0f * 2)/2, 48.0f)] forState:UIControlStateNormal];
- [_sendGiftButton setTitle:@"打赏一下ta" forState:UIControlStateNormal];
- [_sendGiftButton addTarget:self action:@selector(sendGiftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _sendGiftButton;
- }
- @end
|