Commit 9155725f by suolong

完善主播端的礼物互动

parent d9e1a5b9
Showing with 459 additions and 1 deletions
......@@ -115,6 +115,7 @@
#define ROOM_CID_LINKMIC_CHANGE 30012 // 麦位列表存在变化
#define USER_ACCOUNT_CHANGE 12000 // 推送用户账户发生变化
#define ROOM_CID_GIFT_INTERACT_TASK_CHANGED 12002 // 礼物互动任务达成变化
#define ROOM_CID_REALTIME_ACTIVITY_INFO 10091 // 直播间实时活动
#define ROOM_CID_LIVE_ALERT 10090 // 接收到直播弹窗通知
......@@ -133,4 +134,3 @@
......@@ -1667,6 +1667,7 @@
BED65A782C5B745F00668116 /* FUSLiveFunctionLayerView.m in Sources */ = {isa = PBXBuildFile; fileRef = BED657A32C5B745D00668116 /* FUSLiveFunctionLayerView.m */; };
BED65A792C5B745F00668116 /* FUSLiveFunctionView.h in Headers */ = {isa = PBXBuildFile; fileRef = BED657A42C5B745D00668116 /* FUSLiveFunctionView.h */; };
BED65A7A2C5B745F00668116 /* FUSLiveFunctionView.m in Sources */ = {isa = PBXBuildFile; fileRef = BED657A52C5B745D00668116 /* FUSLiveFunctionView.m */; };
C0A1B2C32F6A000100AAAA03 /* FUSLiveGiftInteractTaskPanelView.m in Sources */ = {isa = PBXBuildFile; fileRef = C0A1B2C32F6A000100AAAA02 /* FUSLiveGiftInteractTaskPanelView.m */; };
BED65A7B2C5B745F00668116 /* FUSLiveLoadingView.h in Headers */ = {isa = PBXBuildFile; fileRef = BED657A72C5B745D00668116 /* FUSLiveLoadingView.h */; };
BED65A7C2C5B745F00668116 /* FUSLiveLoadingView.m in Sources */ = {isa = PBXBuildFile; fileRef = BED657A82C5B745D00668116 /* FUSLiveLoadingView.m */; };
BED65A7E2C5B745F00668116 /* FUSLiveMinimizeView.h in Headers */ = {isa = PBXBuildFile; fileRef = BED657AB2C5B745D00668116 /* FUSLiveMinimizeView.h */; };
......@@ -4090,6 +4091,8 @@
BED657A32C5B745D00668116 /* FUSLiveFunctionLayerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FUSLiveFunctionLayerView.m; sourceTree = "<group>"; };
BED657A42C5B745D00668116 /* FUSLiveFunctionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FUSLiveFunctionView.h; sourceTree = "<group>"; };
BED657A52C5B745D00668116 /* FUSLiveFunctionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FUSLiveFunctionView.m; sourceTree = "<group>"; };
C0A1B2C32F6A000100AAAA01 /* FUSLiveGiftInteractTaskPanelView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FUSLiveGiftInteractTaskPanelView.h; sourceTree = "<group>"; };
C0A1B2C32F6A000100AAAA02 /* FUSLiveGiftInteractTaskPanelView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FUSLiveGiftInteractTaskPanelView.m; sourceTree = "<group>"; };
BED657A72C5B745D00668116 /* FUSLiveLoadingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FUSLiveLoadingView.h; sourceTree = "<group>"; };
BED657A82C5B745D00668116 /* FUSLiveLoadingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FUSLiveLoadingView.m; sourceTree = "<group>"; };
BED657A92C5B745D00668116 /* FUSLiveLoadingView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FUSLiveLoadingView.xib; sourceTree = "<group>"; };
......@@ -7392,6 +7395,7 @@
BEEAB2502D337F87008CD059 /* AnchorReward */,
00F0A0102F5F0A1B00C0FFEE /* PayRoom */,
BEB504712D2E8FD100EA6E6F /* LiveThemeView */,
C0A1B2C32F6A000100AAAA00 /* GiftInteract */,
BED655C12C5B745D00668116 /* Activity */,
BED655DC2C5B745D00668116 /* AudienceListView */,
BED656122C5B745D00668116 /* ChatInputView */,
......@@ -7419,6 +7423,15 @@
path = FunctionView;
sourceTree = "<group>";
};
C0A1B2C32F6A000100AAAA00 /* GiftInteract */ = {
isa = PBXGroup;
children = (
C0A1B2C32F6A000100AAAA01 /* FUSLiveGiftInteractTaskPanelView.h */,
C0A1B2C32F6A000100AAAA02 /* FUSLiveGiftInteractTaskPanelView.m */,
);
path = GiftInteract;
sourceTree = "<group>";
};
BED657AA2C5B745D00668116 /* LoadingView */ = {
isa = PBXGroup;
children = (
......@@ -10760,6 +10773,7 @@
BED659E42C5B745F00668116 /* FUSPKHttpHelper.m in Sources */,
BED658BA2C5B745E00668116 /* FUSHalfWebViewCollectionViewCell.m in Sources */,
BED65A7A2C5B745F00668116 /* FUSLiveFunctionView.m in Sources */,
C0A1B2C32F6A000100AAAA03 /* FUSLiveGiftInteractTaskPanelView.m in Sources */,
004773412F5EBADE00E46A79 /* FUSNewUserSevenDayCheckInControl.swift in Sources */,
BED658FF2C5B745E00668116 /* FUSLiveChatInputBulletsListCell.m in Sources */,
BED6599A2C5B745E00668116 /* FUSAgoraHelper.m in Sources */,
{
"images" : [
{
"filename" : "Live_bottom_actIcon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Live_bottom_actIcon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Live_bottom_actIcon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "Live_bottom_actYes.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Live_bottom_actYes@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Live_bottom_actYes@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -97,6 +97,7 @@ static NSInteger const FUSLiveGiftInteractMaxItemCount = 6;
if (roomInfo.stateSwitch) {
roomInfo.stateSwitch.giftinteractionstate = switchState;
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"FUSGiftInteractSwitchDidChangeNotification" object:nil userInfo:@{@"switchState": @(switchState)}];
[weakCell fus_setupWithEnabled:switchState];
[weakCell fus_setSwitchUserInteractionEnabled:YES];
} failure:^(NSString *msg, NSInteger code) {
......
......@@ -9,6 +9,15 @@ NS_ASSUME_NONNULL_BEGIN
/// 互动描述
@property (nonatomic, copy) NSString *name;
/// 任务ID(任务列表接口返回)
@property (nonatomic, copy) NSString *taskId;
/// 用户ID(任务列表接口返回)
@property (nonatomic, copy) NSString *userId;
/// 用户头像(任务列表接口返回)
@property (nonatomic, copy) NSString *userFace;
/// 用户昵称(任务列表接口返回)
@property (nonatomic, copy) NSString *userNickname;
/// 礼物ID
@property (nonatomic, copy) NSString *giftId;
/// 礼物图标URL
......
......@@ -2,4 +2,14 @@
@implementation FUSLiveGiftInteractSettingItemModel
+ (NSDictionary *)modelCustomPropertyMapper {
return @{
@"name": @[@"name", @"action"],
@"taskId": @[@"taskId", @"taskid"],
@"userId": @[@"userId", @"userid"],
@"userFace": @[@"userFace", @"userface"],
@"userNickname": @[@"userNickname", @"usernickname"]
};
}
@end
......@@ -98,12 +98,15 @@
#import "FUSLiveReleasePunishmentView.h"
#import "FUSLivePunishListAlertView.h"
#import "FUSLivePunishmentManager.h"
#import "FUSLiveGiftInteractTaskPanelView.h"
#import "FUSLiveGiftInteractSettingItemModel.h"
// 粒子发射器 cell 重用标识符
#define EMITTER_REUSE_IDENTIFIER @"emitterReuseIdentifier"
// segmentView切换通知
NSString * const kClickCloseBtnNotification = @"kClickCloseBtnNotification";
static NSString * const FUSGiftInteractSwitchDidChangeNotification = @"FUSGiftInteractSwitchDidChangeNotification";
@interface FUSLiveFunctionView ()
<
......@@ -218,6 +221,13 @@ BDAlphaPlayerMetalViewDelegate
// 显示各种PK的入口
@property (nonatomic,strong) FUSPKControlAlertView *pkStyleView;
/// 礼物互动任务面板(最多展示6条,空态显示“暂无”)
@property (nonatomic, strong) FUSLiveGiftInteractTaskPanelView *giftInteractTaskPanelView;
/// 当前面板展示的任务列表(按 addtime 排序)
@property (nonatomic, strong) NSMutableArray<FUSLiveGiftInteractSettingItemModel *> *giftInteractTaskVisibleList;
/// 被点击“消失”的任务集合(本场直播内不再展示)
@property (nonatomic, strong) NSMutableSet<NSString *> *giftInteractDismissedTaskIdSet;
// 标记键盘是否弹起
@property (nonatomic,assign) BOOL isKeyboard;
......@@ -2727,6 +2737,10 @@ BDAlphaPlayerMetalViewDelegate
// 接收主播直播拍一拍用户消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fus_receivePatAudienceUpNotification:) name:STR(ROOM_CID_receivePatAudience) object:nil];
// 监听礼物互动开关状态变化通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fus_giftInteractSwitchDidChange:) name:FUSGiftInteractSwitchDidChangeNotification object:nil];
// 监听礼物互动任务变化通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fus_receiveGiftInteractTaskChangedNotification:) name:STR(ROOM_CID_GIFT_INTERACT_TASK_CHANGED) object:nil];
// 接收pk惩罚结束的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fus_livePunishFinishNotification:) name:FUSShowRoomSocket.livePunishFinish object:nil];
......@@ -3313,10 +3327,200 @@ BDAlphaPlayerMetalViewDelegate
[weakSelf.specialEffectView fus_removeAllAnimation];
} else {
}
if ([FUSLiveHelper shareInstance].liveType == FUSLiveTypeAnchor) {
FUSRoomInfoModel *roomInfo = [FUSLiveHelper shareInstance].roomInfoModel;
BOOL giftInteractEnabled = roomInfo.stateSwitch ? roomInfo.stateSwitch.giftinteractionstate : NO;
if (giftInteractEnabled) {
[weakSelf fus_refreshGiftInteractTaskListWithDelay:0.6];
}
}
}];
}
}];
}
#pragma mark - GiftInteract
/// 礼物互动开关变更通知回调(来源:设置页切换)
- (void)fus_giftInteractSwitchDidChange:(NSNotification *)notification {
BOOL enabled = [notification.userInfo[@"switchState"] boolValue];
[self fus_updateGiftInteractTaskFeatureEnabled:enabled];
if (enabled) {
[self fus_refreshGiftInteractTaskListWithDelay:0.2];
}
}
/// 礼物互动达成变化(收到后主播刷新任务列表)
- (void)fus_receiveGiftInteractTaskChangedNotification:(NSNotification *)notification {
if (!self.giftInteractTaskPanelView) {
[self fus_updateGiftInteractTaskFeatureEnabled:YES];
}
if (!self.giftInteractTaskPanelView) {
return;
}
[self fus_refreshGiftInteractTaskListWithDelay:0.2];
}
/// 开关礼物互动任务展示能力(创建/销毁面板)
- (void)fus_updateGiftInteractTaskFeatureEnabled:(BOOL)enabled {
if ([FUSLiveHelper shareInstance].liveType != FUSLiveTypeAnchor) {
enabled = NO;
}
if (!enabled) {
[self.giftInteractTaskPanelView removeFromSuperview];
self.giftInteractTaskPanelView = nil;
[self.giftInteractTaskVisibleList removeAllObjects];
return;
}
if (!self.giftInteractDismissedTaskIdSet) {
self.giftInteractDismissedTaskIdSet = [NSMutableSet set];
}
if (!self.giftInteractTaskVisibleList) {
self.giftInteractTaskVisibleList = [NSMutableArray array];
}
if (!self.giftInteractTaskPanelView) {
self.giftInteractTaskPanelView = [[FUSLiveGiftInteractTaskPanelView alloc] initWithFrame:CGRectZero];
__weak typeof(self) weakSelf = self;
self.giftInteractTaskPanelView.doneHandler = ^(NSInteger index) {
[weakSelf fus_onGiftInteractTaskDismissAtIndex:index];
};
[[self fus_viewWithLayer:FUSLiveFunctionLayerManualPopView] addSubview:self.giftInteractTaskPanelView];
}
[self fus_updateGiftInteractTaskPanelLayout];
if (self.giftInteractTaskVisibleList.count == 0) {
[self fus_refreshGiftInteractTaskListWithDelay:0.2];
}
}
/// 刷新任务列表(支持延迟合并多次触发)
- (void)fus_refreshGiftInteractTaskListWithDelay:(NSTimeInterval)delay {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(fus_requestGiftInteractTaskList) object:nil];
if (delay <= 0) {
[self fus_requestGiftInteractTaskList];
} else {
[self performSelector:@selector(fus_requestGiftInteractTaskList) withObject:nil afterDelay:delay];
}
}
/// 请求任务列表接口,并更新面板展示(最多6条,按时间排序)
- (void)fus_requestGiftInteractTaskList {
if ([FUSLiveHelper shareInstance].liveType != FUSLiveTypeAnchor) {
return;
}
FUSRoomInfoModel *roomInfo = [FUSLiveHelper shareInstance].roomInfoModel;
BOOL enabled = roomInfo.stateSwitch ? roomInfo.stateSwitch.giftinteractionstate : NO;
if (!enabled) {
return;
}
NSString *uid = FUSCacheDataShare.shareStore.userDetailInfo.uid ?: @"";
NSString *roomId = roomInfo.roomId ?: @"";
NSString *channelId = roomInfo.channelId ?: @"";
__weak typeof(self) weakSelf = self;
[FUSLiveHttpHelper fus_requestGiftInteractTaskListWithUid:uid RoomId:roomId channelId:channelId succeed:^(NSDictionary *dataDict) {
NSArray *rawList = [dataDict[@"dataList"] isKindOfClass:NSArray.class] ? dataDict[@"dataList"] : @[];
NSMutableArray<FUSLiveGiftInteractSettingItemModel *> *models = [NSMutableArray arrayWithCapacity:rawList.count];
for (NSDictionary *dict in rawList) {
if (![dict isKindOfClass:NSDictionary.class]) {
continue;
}
FUSLiveGiftInteractSettingItemModel *model = [FUSLiveGiftInteractSettingItemModel fus_modelWithDict:dict];
NSString *identity = model.taskId.length ? model.taskId : model.sid;
if (identity.length && [weakSelf.giftInteractDismissedTaskIdSet containsObject:identity]) {
continue;
}
[models addObject:model];
}
[models sortUsingComparator:^NSComparisonResult(FUSLiveGiftInteractSettingItemModel *obj1, FUSLiveGiftInteractSettingItemModel *obj2) {
long long t1 = (long long)[obj1.addtime doubleValue];
long long t2 = (long long)[obj2.addtime doubleValue];
if (t1 != 0 || t2 != 0) {
if (t1 < t2) return NSOrderedAscending;
if (t1 > t2) return NSOrderedDescending;
return NSOrderedSame;
}
return [obj1.addtime compare:obj2.addtime];
}];
if (models.count > 6) {
[models removeObjectsInRange:NSMakeRange(6, models.count - 6)];
}
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.giftInteractTaskVisibleList removeAllObjects];
[weakSelf.giftInteractTaskVisibleList addObjectsFromArray:models];
[weakSelf fus_reloadGiftInteractTaskPanel];
});
} failure:^(NSString *msg, NSInteger code) {
}];
}
/// 将模型列表转为面板展示文案并刷新布局
- (void)fus_reloadGiftInteractTaskPanel {
if (!self.giftInteractTaskPanelView) {
return;
}
NSMutableArray<NSString *> *texts = [NSMutableArray arrayWithCapacity:self.giftInteractTaskVisibleList.count];
for (FUSLiveGiftInteractSettingItemModel *model in self.giftInteractTaskVisibleList) {
NSString *nickname = model.userNickname ?: @"";
NSString *action = model.name ?: @"";
NSString *text = nil;
if (nickname.length > 0) {
text = [NSString stringWithFormat:@"%@:%@", nickname, action];
} else {
text = action;
}
[texts addObject:text ?: @""];
}
[self.giftInteractTaskPanelView fus_updateWithTaskTexts:texts];
[self fus_updateGiftInteractTaskPanelLayout];
}
/// 计算并刷新任务面板位置(贴近聊天区上方,避免遮挡头部)
- (void)fus_updateGiftInteractTaskPanelLayout {
if (!self.giftInteractTaskPanelView) {
return;
}
UIView *containerView = [self fus_viewWithLayer:FUSLiveFunctionLayerManualPopView];
CGFloat width = 140;
NSInteger count = MIN(6, self.giftInteractTaskVisibleList.count);
CGFloat height = 110;
if (count > 0) {
height = 110 + (110.0 / 6.0) * count;
}
CGFloat x = CGRectGetWidth(containerView.bounds) - 15 - width;
CGFloat y = 0;
if (self.anchorRewardView.superview) {
CGRect rewardRect = [containerView convertRect:self.anchorRewardView.frame fromView:self.anchorRewardView.superview];
y = CGRectGetMinY(rewardRect);
} else if (self.pusherPopularView.superview) {
CGRect popRect = [containerView convertRect:self.pusherPopularView.frame fromView:self.pusherPopularView.superview];
y = CGRectGetMaxY(popRect);
} else {
y = 0;
}
self.giftInteractTaskPanelView.frame = CGRectMake(x, y, width, height);
}
/// 点击“消失”:移除当前任务并加入本场的忽略集合
- (void)fus_onGiftInteractTaskDismissAtIndex:(NSInteger)index {
if (index < 0 || index >= self.giftInteractTaskVisibleList.count) {
return;
}
FUSLiveGiftInteractSettingItemModel *model = self.giftInteractTaskVisibleList[index];
NSString *identity = model.taskId.length ? model.taskId : model.sid;
if (identity.length) {
[self.giftInteractDismissedTaskIdSet addObject:identity];
}
[self.giftInteractTaskVisibleList removeObjectAtIndex:index];
[self fus_reloadGiftInteractTaskPanel];
}
/**
......@@ -5624,6 +5828,9 @@ BDAlphaPlayerMetalViewDelegate
[FUSLivePunishmentManager fus_requestLivePunishDataSyncWithDelay:5];
}
}
BOOL giftInteractEnabled = model.stateSwitch ? model.stateSwitch.giftinteractionstate : NO;
[self fus_updateGiftInteractTaskFeatureEnabled:giftInteractEnabled];
}
/**
......@@ -5704,6 +5911,8 @@ BDAlphaPlayerMetalViewDelegate
[self.realtimeActivityTimer invalidate];
self.realtimeActivityTimer = nil;
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(fus_requestGiftInteractTaskList) object:nil];
[self.emitter fus_cleanAllEmitter];
[self.pusherChatTableView fus_clearTableView];
......
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface FUSLiveGiftInteractTaskPanelView : UIView
/// 点击“消失”回调,index 对应 taskTexts 的下标
@property (nonatomic, copy, nullable) void (^doneHandler)(NSInteger index);
/// 刷新展示文本(最多展示调用方传入的数量)
- (void)fus_updateWithTaskTexts:(NSArray<NSString *> *)taskTexts;
@end
NS_ASSUME_NONNULL_END
#import "FUSLiveGiftInteractTaskPanelView.h"
@interface FUSLiveGiftInteractTaskPanelView ()
/// 顶部标题栏
@property (nonatomic, strong) UIView *headerView;
/// 顶部icon
@property (nonatomic, strong) UIImageView *headerIconView;
/// 顶部标题
@property (nonatomic, strong) UILabel *headerTitleLabel;
/// 空态文案(当 taskTexts 为空时显示)
@property (nonatomic, strong) UILabel *emptyLabel;
/// 当前展示的文本数组
@property (nonatomic, copy) NSArray<NSString *> *taskTexts;
/// 左侧文本 label 列表(按 taskTexts 数量动态增减)
@property (nonatomic, strong) NSMutableArray<UILabel *> *textLabels;
/// 右侧“消失”按钮列表(按 taskTexts 数量动态增减)
@property (nonatomic, strong) NSMutableArray<UIButton *> *doneButtons;
@end
@implementation FUSLiveGiftInteractTaskPanelView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.35];
self.layer.cornerRadius = 8;
self.clipsToBounds = YES;
self.userInteractionEnabled = YES;
self.headerView = [[UIView alloc] initWithFrame:CGRectZero];
self.headerView.backgroundColor = [UIColor colorWithHex:@"36E6ED" alpha:1];
[self addSubview:self.headerView];
self.headerIconView = [[UIImageView alloc] initWithFrame:CGRectZero];
self.headerIconView.contentMode = UIViewContentModeScaleAspectFit;
self.headerIconView.image = [FUSShowRoomCenterBunble imageNamed:@"Live_bottom_actIcon"];
[self.headerView addSubview:self.headerIconView];
self.headerTitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.headerTitleLabel.text = [NSString fus_localString:@"互动"];
self.headerTitleLabel.font = [UIFont fus_themeFont:15];
self.headerTitleLabel.textColor = UIColor.blackColor;
[self.headerView addSubview:self.headerTitleLabel];
self.textLabels = [NSMutableArray array];
self.doneButtons = [NSMutableArray array];
self.emptyLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.emptyLabel.text = [NSString fus_localString:@"暂无"];
self.emptyLabel.textAlignment = NSTextAlignmentCenter;
self.emptyLabel.font = [UIFont fus_themeFont:12];
self.emptyLabel.textColor = UIColor.whiteColor;
[self addSubview:self.emptyLabel];
[self fus_updateWithTaskTexts:@[]];
return self;
}
/// 刷新内容并驱动视图子控件数量与布局更新
- (void)fus_updateWithTaskTexts:(NSArray<NSString *> *)taskTexts {
self.taskTexts = taskTexts ?: @[];
NSInteger targetCount = self.taskTexts.count;
while (self.textLabels.count > targetCount) {
UILabel *label = self.textLabels.lastObject;
[label removeFromSuperview];
[self.textLabels removeLastObject];
}
while (self.doneButtons.count > targetCount) {
UIButton *btn = self.doneButtons.lastObject;
[btn removeFromSuperview];
[self.doneButtons removeLastObject];
}
while (self.textLabels.count < targetCount) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont fus_themeFont:12];
label.textColor = UIColor.whiteColor;
label.numberOfLines = 1;
[self addSubview:label];
[self.textLabels addObject:label];
}
while (self.doneButtons.count < targetCount) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *img = [FUSShowRoomCenterBunble imageNamed:@"Live_bottom_actYes"];
[btn setImage:img forState:UIControlStateNormal];
[btn addTarget:self action:@selector(fus_onClickDone:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
[self.doneButtons addObject:btn];
}
for (NSInteger i = 0; i < targetCount; i++) {
UILabel *label = self.textLabels[i];
label.text = self.taskTexts[i] ?: @"";
UIButton *btn = self.doneButtons[i];
btn.tag = i;
}
self.emptyLabel.hidden = (targetCount > 0);
[self setNeedsLayout];
}
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat headerH = 30;
CGFloat padding = 8;
CGFloat buttonSize = 18;
self.headerView.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), headerH);
CGFloat iconSize = 16;
CGFloat spacing = 4;
CGSize titleSize = [self.headerTitleLabel sizeThatFits:CGSizeMake(CGFLOAT_MAX, headerH)];
CGFloat groupW = iconSize + spacing + titleSize.width;
CGFloat groupX = (CGRectGetWidth(self.headerView.bounds) - groupW) * 0.5;
if (groupX < 0) {
groupX = 0;
}
self.headerIconView.frame = CGRectMake(groupX, (headerH - iconSize) * 0.5, iconSize, iconSize);
self.headerTitleLabel.frame = CGRectMake(CGRectGetMaxX(self.headerIconView.frame) + spacing, 0, titleSize.width, headerH);
CGFloat contentTop = CGRectGetMaxY(self.headerView.frame);
if (self.taskTexts.count == 0) {
self.emptyLabel.frame = CGRectMake(0, contentTop, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) - contentTop);
return;
}
self.emptyLabel.frame = CGRectZero;
CGFloat labelX = padding;
CGFloat buttonX = CGRectGetWidth(self.bounds) - padding - buttonSize;
CGFloat labelW = buttonX - labelX - 8;
CGFloat availableH = CGRectGetHeight(self.bounds) - contentTop - padding * 2;
CGFloat rowHeight = (availableH > 0 ? (availableH / self.taskTexts.count) : 0);
for (NSInteger i = 0; i < self.taskTexts.count; i++) {
CGFloat y = contentTop + padding + i * rowHeight;
UILabel *label = self.textLabels[i];
label.frame = CGRectMake(labelX, y, labelW, rowHeight);
UIButton *btn = self.doneButtons[i];
btn.frame = CGRectMake(buttonX, y + (rowHeight - buttonSize) * 0.5, buttonSize, buttonSize);
}
}
/// 点击“消失”
- (void)fus_onClickDone:(UIButton *)sender {
if (self.doneHandler) {
self.doneHandler(sender.tag);
}
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment