添加删除按钮

This commit is contained in:
2025-12-15 18:32:54 +08:00
parent 053001170a
commit 05b9a0b823
3 changed files with 47 additions and 3 deletions

View File

@@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)emojiPanelView:(KBEmojiPanelView *)panel didSelectEmoji:(NSString *)emoji;
- (void)emojiPanelViewDidRequestClose:(KBEmojiPanelView *)panel;
- (void)emojiPanelViewDidTapSearch:(KBEmojiPanelView *)panel;
@optional
- (void)emojiPanelViewDidTapDelete:(KBEmojiPanelView *)panel;
@end
@interface KBEmojiPanelView : UIView

View File

@@ -19,6 +19,7 @@
@property (nonatomic, strong) UIView *bottomBar;
@property (nonatomic, strong) UIScrollView *tabScrollView;
@property (nonatomic, strong) UIStackView *tabStackView;
@property (nonatomic, strong) UIButton *deleteButton;
//@property (nonatomic, strong) UIButton *searchButton;
@property (nonatomic, strong) NSArray<UIButton *> *tabButtons;
@property (nonatomic, strong) KBEmojiDataProvider *dataProvider;
@@ -119,6 +120,15 @@
self.tabStackView.alignment = UIStackViewAlignmentFill;
[self.tabScrollView addSubview:self.tabStackView];
self.deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.deleteButton.layer.cornerRadius = 16;
self.deleteButton.layer.masksToBounds = YES;
self.deleteButton.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
[self.deleteButton setTitle:@"⌫" forState:UIControlStateNormal];
[self.deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.deleteButton addTarget:self action:@selector(onDelete) forControlEvents:UIControlEventTouchUpInside];
[self.bottomBar addSubview:self.deleteButton];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(12);
make.right.equalTo(self.mas_right).offset(-12);
@@ -140,8 +150,7 @@
[self.tabScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.bottomBar.mas_left).offset(12);
// make.right.equalTo(self.searchButton.mas_left).offset(-12);
make.right.equalTo(self.bottomBar.mas_right).offset(-12);
make.right.equalTo(self.deleteButton.mas_left).offset(-12);
make.top.equalTo(self.bottomBar.mas_top).offset(4);
make.bottom.equalTo(self.bottomBar.mas_bottom).offset(-4);
}];
@@ -151,6 +160,13 @@
make.height.equalTo(self.tabScrollView);
}];
[self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.bottomBar.mas_right).offset(-12);
make.centerY.equalTo(self.bottomBar);
make.width.mas_equalTo(44);
make.height.equalTo(self.tabScrollView);
}];
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipe:)];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:leftSwipe];
@@ -167,7 +183,6 @@
}
- (void)updateTabButtonCornerRadii {
if (self.tabButtons.count == 0) { return; }
for (UIButton *btn in self.tabButtons) {
CGFloat radius = MIN(CGRectGetHeight(btn.bounds), CGRectGetWidth(btn.bounds)) / 2.0;
if (radius <= 0) { continue; }
@@ -176,6 +191,15 @@
btn.layer.cornerCurve = kCACornerCurveContinuous;
}
}
if (self.deleteButton) {
CGFloat radius = MIN(CGRectGetHeight(self.deleteButton.bounds), CGRectGetWidth(self.deleteButton.bounds)) / 2.0;
if (radius > 0) {
self.deleteButton.layer.cornerRadius = radius;
if (@available(iOS 13.0, *)) {
self.deleteButton.layer.cornerCurve = kCACornerCurveContinuous;
}
}
}
}
- (void)registerNotifications {
@@ -283,6 +307,12 @@
}
}
- (void)onDelete {
if ([self.delegate respondsToSelector:@selector(emojiPanelViewDidTapDelete:)]) {
[self.delegate emojiPanelViewDidTapDelete:self];
}
}
- (void)onTabTapped:(UIButton *)sender {
[self updateSelectionToIndex:sender.tag];
}
@@ -321,6 +351,11 @@
self.tabNormalColor = [UIColor colorWithWhite:1 alpha:0.08];
self.tabSelectedColor = theme.accentColor ?: [UIColor colorWithWhite:1 alpha:0.25];
[self updateTabHighlightStates];
if (self.deleteButton) {
self.deleteButton.backgroundColor = self.tabNormalColor;
UIColor *deleteTitleColor = theme.keyTextColor ?: [UIColor whiteColor];
[self.deleteButton setTitleColor:deleteTitleColor forState:UIControlStateNormal];
}
if (self.magnifierView) {
self.magnifierView.backgroundColor = theme.keyBackground ?: [UIColor colorWithWhite:1 alpha:0.9];
}