Commit fc0f0608 by suolong

添加弹窗ui

parent 6121e428
{
"images" : [
{
"filename" : "Live_bottom_ticket.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Live_bottom_ticket@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Live_bottom_ticket@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 居中模糊信息弹窗(空白区域不可关闭,仅展示内容用)
@interface FUSLiveShowTimeFrostCardPopView : UIView
/// 展示到指定父视图(已存在则复用)
+ (instancetype)fus_showOnView:(UIView *)onView;
/// 主动关闭弹窗
- (void)fus_dismiss;
@end
NS_ASSUME_NONNULL_END
#import "FUSLiveShowTimeFrostCardPopView.h"
#import <Masonry/Masonry.h>
#import <FUSFoundation/FUSFoundation.h>
static const NSInteger kFUSLiveShowTimeFrostCardPopViewTag = 8817402;
@interface FUSLiveShowTimeFrostCardPopView ()
/// 背景遮罩按钮(拦截点击,空白区域不关闭)
@property (nonatomic, strong) UIButton *bgBtn;
/// 模糊卡片承载容器
@property (nonatomic, strong) UIView *contentView;
/// 毛玻璃视图(系统暗色材质)
@property (nonatomic, strong) UIVisualEffectView *blurView;
/// 内容纵向居中动画约束
@property (nonatomic, strong) MASConstraint *contentCenterYConstraint;
@end
@implementation FUSLiveShowTimeFrostCardPopView
/// 展示到指定父视图(存在则复用)
+ (instancetype)fus_showOnView:(UIView *)onView {
if (!onView) return nil;
FUSLiveShowTimeFrostCardPopView *exist = [onView viewWithTag:kFUSLiveShowTimeFrostCardPopViewTag];
if ([exist isKindOfClass:FUSLiveShowTimeFrostCardPopView.class]) {
[onView bringSubviewToFront:exist];
return exist;
}
FUSLiveShowTimeFrostCardPopView *v = [[FUSLiveShowTimeFrostCardPopView alloc] initWithFrame:CGRectZero];
v.tag = kFUSLiveShowTimeFrostCardPopViewTag;
[onView addSubview:v];
[v mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(onView);
}];
return v;
}
/// 初始化并设置布局与入场动画
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) return nil;
self.bgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.bgBtn.backgroundColor = [UIColor colorWithWhite:0 alpha:0.35];
[self addSubview:self.bgBtn];
self.contentView = [[UIView alloc] init];
self.contentView.layer.cornerRadius = 12;
self.contentView.layer.masksToBounds = YES;
[self addSubview:self.contentView];
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemThinMaterialDark];
self.blurView = [[UIVisualEffectView alloc] initWithEffect:effect];
[self.contentView addSubview:self.blurView];
[self.bgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
self.contentCenterYConstraint = make.centerY.equalTo(self).offset(UIView.fus_screenH);
make.width.mas_equalTo(MIN(UIView.fus_screenW - 32, 320));
make.height.mas_equalTo(MIN(UIView.fus_screenH * 0.5, 360));
}];
[self.blurView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
}];
[self.superview layoutIfNeeded];
[self.contentCenterYConstraint setOffset:0];
[UIView animateWithDuration:0.3 animations:^{
[self.superview layoutIfNeeded];
}];
return self;
}
/// 关闭弹窗,执行退场动画后移除
- (void)fus_dismiss {
[self.contentCenterYConstraint setOffset:UIView.fus_screenH];
[UIView animateWithDuration:0.25 animations:^{
[self layoutIfNeeded];
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
@end
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 底部确认弹窗:展示 MVP 头像/标识/昵称,仅“确认”可关闭
@interface FUSLiveShowTimeMVPConfirmPopView : UIView
/// 展示到指定父视图(存在则复用)
+ (instancetype)fus_showOnView:(UIView *)onView;
/// 更新头像/昵称/MVP 标签文案
- (void)fus_updateAvatarURL:(nullable NSString *)url nickname:(nullable NSString *)nickname tagText:(nullable NSString *)tagText;
/// 设置确认按钮点击回调
- (void)fus_setConfirmHandler:(void (^)(void))confirmHandler;
/// 主动关闭弹窗
- (void)fus_dismiss;
@end
NS_ASSUME_NONNULL_END
#import "FUSLiveShowTimeMVPConfirmPopView.h"
#import <Masonry/Masonry.h>
#import <FUSFoundation/FUSFoundation.h>
#import <FUSCommon/FUSCommon.h>
static const NSInteger kFUSLiveShowTimeMVPConfirmPopViewTag = 8817401;
@interface FUSLiveShowTimeMVPConfirmPopView ()
/// 背景遮罩按钮(拦截点击,空白区域不关闭)
@property (nonatomic, strong) UIButton *bgBtn;
/// 底部内容容器(白底圆角)
@property (nonatomic, strong) UIView *contentView;
/// 内容容器底约束(控制上/下滑动画)
@property (nonatomic, strong) MASConstraint *contentBottomConstraint;
/// 头部占位视图(用于头像悬停效果)
@property (nonatomic, strong) UIView *headerHolderView;
/// MVP 头像
@property (nonatomic, strong) UIImageView *avatarView;
/// MVP 标识标签
@property (nonatomic, strong) UILabel *mvpTagLabel;
/// 昵称标签
@property (nonatomic, strong) UILabel *nicknameLabel;
/// 确认按钮(唯一可关闭入口)
@property (nonatomic, strong) UIButton *confirmBtn;
/// 确认回调
@property (nonatomic, copy) void (^confirmHandler)(void);
@end
@implementation FUSLiveShowTimeMVPConfirmPopView
/// 展示到指定父视图(存在则复用,不重复创建)
+ (instancetype)fus_showOnView:(UIView *)onView {
if (!onView) return nil;
FUSLiveShowTimeMVPConfirmPopView *exist = [onView viewWithTag:kFUSLiveShowTimeMVPConfirmPopViewTag];
if ([exist isKindOfClass:FUSLiveShowTimeMVPConfirmPopView.class]) {
[onView bringSubviewToFront:exist];
return exist;
}
FUSLiveShowTimeMVPConfirmPopView *v = [[FUSLiveShowTimeMVPConfirmPopView alloc] initWithFrame:CGRectZero];
v.tag = kFUSLiveShowTimeMVPConfirmPopViewTag;
[onView addSubview:v];
[v mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(onView);
}];
return v;
}
/// 初始化布局与约束,准备入场动画
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) return nil;
self.bgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.bgBtn.backgroundColor = [UIColor colorWithWhite:0 alpha:0.35];
[self addSubview:self.bgBtn];
CGFloat safeBottom = UIView.fus_SafeBottom;
CGFloat contentH = MIN(300, UIView.fus_screenH * 0.45) + safeBottom;
self.contentView = [[UIView alloc] init];
self.contentView.backgroundColor = UIColor.whiteColor;
self.contentView.layer.cornerRadius = 16;
self.contentView.layer.masksToBounds = YES;
if (@available(iOS 11.0, *)) {
self.contentView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
}
[self addSubview:self.contentView];
self.headerHolderView = [[UIView alloc] init];
[self.contentView addSubview:self.headerHolderView];
self.avatarView = [[UIImageView alloc] init];
self.avatarView.layer.cornerRadius = 28;
self.avatarView.layer.masksToBounds = YES;
self.avatarView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
[self addSubview:self.avatarView];
self.mvpTagLabel = [[UILabel alloc] init];
self.mvpTagLabel.text = @"MVP";
self.mvpTagLabel.textAlignment = NSTextAlignmentCenter;
self.mvpTagLabel.font = [UIFont fus_themeBoldFont:12];
self.mvpTagLabel.textColor = UIColor.blackColor;
self.mvpTagLabel.backgroundColor = [UIColor colorWithHex:@"#52DDE2"];
self.mvpTagLabel.layer.cornerRadius = 10;
self.mvpTagLabel.layer.masksToBounds = YES;
[self.contentView addSubview:self.mvpTagLabel];
self.nicknameLabel = [[UILabel alloc] init];
self.nicknameLabel.textAlignment = NSTextAlignmentCenter;
self.nicknameLabel.font = [UIFont fus_themeBoldFont:16];
self.nicknameLabel.textColor = [UIColor colorWithHex:@"#333333"];
[self.contentView addSubview:self.nicknameLabel];
self.confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[self.confirmBtn setTitle:[NSString fus_localString:@"确认"] forState:UIControlStateNormal];
self.confirmBtn.titleLabel.font = [UIFont fus_themeBoldFont:16];
[self.confirmBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
self.confirmBtn.backgroundColor = [UIColor colorWithHex:@"#52DDE2"];
self.confirmBtn.layer.cornerRadius = 24;
self.confirmBtn.layer.masksToBounds = YES;
[self.confirmBtn addTarget:self action:@selector(onConfirm) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.confirmBtn];
[self.bgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.height.mas_equalTo(contentH);
self.contentBottomConstraint = make.bottom.equalTo(self).offset(contentH);
}];
[self.headerHolderView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView);
make.top.equalTo(self.contentView);
make.height.mas_equalTo(48);
}];
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.contentView);
make.centerY.equalTo(self.contentView.mas_top).offset(0);
make.size.mas_equalTo(CGSizeMake(56, 56));
}];
[self.mvpTagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.contentView);
make.top.equalTo(self.headerHolderView.mas_bottom).offset(16);
make.size.mas_equalTo(CGSizeMake(54, 20));
}];
[self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(16);
make.right.equalTo(self.contentView).offset(-16);
make.top.equalTo(self.mvpTagLabel.mas_bottom).offset(8);
make.height.mas_equalTo(22);
}];
[self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(24);
make.right.equalTo(self.contentView).offset(-24);
make.height.mas_equalTo(48);
make.bottom.equalTo(self.contentView).offset(-(safeBottom + 16));
}];
return self;
}
/// 点击确认:回调并关闭弹窗
- (void)onConfirm {
if (self.confirmHandler) {
self.confirmHandler();
}
[self fus_dismiss];
}
/// 更新头像/昵称/MVP 标识文案
- (void)fus_updateAvatarURL:(nullable NSString *)url nickname:(nullable NSString *)nickname tagText:(nullable NSString *)tagText {
if (url.length > 0) {
[self.avatarView setWebImageWithSubURLString:url placeholder:[UIImage fus_defaultIcon]];
}
self.nicknameLabel.text = (nickname.length > 0 ? nickname : @"");
self.mvpTagLabel.text = (tagText.length > 0 ? tagText : @"MVP");
}
/// 设置确认按钮回调
- (void)fus_setConfirmHandler:(void (^)(void))confirmHandler {
self.confirmHandler = [confirmHandler copy];
}
/// 关闭弹窗:下滑动画后移除
- (void)fus_dismiss {
CGFloat safeBottom = UIView.fus_SafeBottom;
CGFloat contentH = MIN(300, UIView.fus_screenH * 0.45) + safeBottom;
[self.contentBottomConstraint setOffset:contentH];
[UIView animateWithDuration:0.25 animations:^{
[self layoutIfNeeded];
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
@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