66
This commit is contained in:
@@ -7,6 +7,13 @@
|
||||
|
||||
#import "KBSexSelVC.h"
|
||||
|
||||
/// 性别类型
|
||||
typedef NS_ENUM(NSInteger, KBSexOption) {
|
||||
KBSexOptionMale = 0,
|
||||
KBSexOptionFemale,
|
||||
KBSexOptionOther
|
||||
};
|
||||
|
||||
@interface KBSexSelVC ()
|
||||
|
||||
// 顶部区域
|
||||
@@ -38,6 +45,9 @@
|
||||
//@property (nonatomic, strong) CAGradientLayer *topGradientLayer;
|
||||
@property (nonatomic, strong) UIImageView *bgImageView; // 全屏背景图
|
||||
|
||||
/// 当前选中的性别
|
||||
@property (nonatomic, assign) KBSexOption selectedSex;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBSexSelVC
|
||||
@@ -54,6 +64,9 @@
|
||||
make.edges.equalTo(self.view);
|
||||
}];
|
||||
[self setupUI];
|
||||
|
||||
// 默认选中 Male
|
||||
[self kb_updateSelection:KBSexOptionMale];
|
||||
}
|
||||
|
||||
- (void)viewDidLayoutSubviews {
|
||||
@@ -88,7 +101,14 @@
|
||||
|
||||
// 底部按钮
|
||||
[self.view addSubview:self.confirmButton];
|
||||
|
||||
|
||||
// 点击卡片切换选中状态
|
||||
UITapGestureRecognizer *tapMale = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMaleCardTapped)];
|
||||
[self.maleCardView addGestureRecognizer:tapMale];
|
||||
UITapGestureRecognizer *tapFemale = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onFemaleCardTapped)];
|
||||
[self.femaleCardView addGestureRecognizer:tapFemale];
|
||||
UITapGestureRecognizer *tapOther = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onOtherCardTapped)];
|
||||
[self.otherCardView addGestureRecognizer:tapOther];
|
||||
|
||||
|
||||
// 跳过按钮右上角(跟随安全区)
|
||||
@@ -188,6 +208,21 @@
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
/// 点击男生卡片
|
||||
- (void)onMaleCardTapped {
|
||||
[self kb_updateSelection:KBSexOptionMale];
|
||||
}
|
||||
|
||||
/// 点击女生卡片
|
||||
- (void)onFemaleCardTapped {
|
||||
[self kb_updateSelection:KBSexOptionFemale];
|
||||
}
|
||||
|
||||
/// 点击第三性别卡片
|
||||
- (void)onOtherCardTapped {
|
||||
[self kb_updateSelection:KBSexOptionOther];
|
||||
}
|
||||
|
||||
/// 点击跳过
|
||||
- (void)onSkipTapped {
|
||||
// 触发回调,让外部(如 AppDelegate)切换到主 TabBar
|
||||
@@ -208,6 +243,22 @@
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
/// 根据当前选中的性别更新三个卡片的 UI
|
||||
- (void)kb_updateSelection:(KBSexOption)sex {
|
||||
self.selectedSex = sex;
|
||||
|
||||
[self kb_updateCard:self.maleCardView selected:(sex == KBSexOptionMale)];
|
||||
[self kb_updateCard:self.femaleCardView selected:(sex == KBSexOptionFemale)];
|
||||
[self kb_updateCard:self.otherCardView selected:(sex == KBSexOptionOther)];
|
||||
}
|
||||
|
||||
/// 统一设置卡片的选中/未选中样式
|
||||
- (void)kb_updateCard:(UIView *)card selected:(BOOL)selected {
|
||||
card.layer.borderWidth = selected ? 2.0 : 0.0;
|
||||
card.layer.borderColor = selected ? [UIColor colorWithHex:KBColorValue].CGColor : [UIColor clearColor].CGColor;
|
||||
card.backgroundColor = selected ? [UIColor whiteColor] : [UIColor colorWithHex:0xFAFAFA];
|
||||
}
|
||||
|
||||
#pragma mark - Lazy UI
|
||||
|
||||
|
||||
@@ -257,10 +308,12 @@
|
||||
- (UIView *)maleCardView {
|
||||
if (!_maleCardView) {
|
||||
_maleCardView = [UIView new];
|
||||
_maleCardView.backgroundColor = [UIColor whiteColor];
|
||||
// 默认未选中背景
|
||||
_maleCardView.backgroundColor = [UIColor colorWithHex:0xFAFAFA];
|
||||
_maleCardView.layer.cornerRadius = 24.0;
|
||||
_maleCardView.layer.masksToBounds = YES;
|
||||
_maleCardView.layer.borderWidth = 2.0;
|
||||
// 边框样式由 kb_updateSelection 统一控制,这里先不设置宽度
|
||||
_maleCardView.layer.borderWidth = 0.0;
|
||||
_maleCardView.layer.borderColor = [UIColor colorWithHex:KBColorValue].CGColor;
|
||||
}
|
||||
return _maleCardView;
|
||||
|
||||
Reference in New Issue
Block a user