重构
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#import "KBLocalizationManager.h"
|
||||
#import "Masonry.h"
|
||||
#import "KBEmojiCollectionCell.h"
|
||||
#import "KBEmojiBottomBarView.h"
|
||||
|
||||
|
||||
@interface KBEmojiPanelView () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
||||
@@ -16,10 +17,7 @@
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
@property (nonatomic, strong) UIButton *backButton;
|
||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||
@property (nonatomic, strong) UIView *bottomBar;
|
||||
@property (nonatomic, strong) UIScrollView *tabScrollView;
|
||||
@property (nonatomic, strong) UIStackView *tabStackView;
|
||||
@property (nonatomic, strong) UIButton *deleteButton;
|
||||
@property (nonatomic, strong) KBEmojiBottomBarView *bottomBar;
|
||||
//@property (nonatomic, strong) UIButton *searchButton;
|
||||
@property (nonatomic, strong) NSArray<UIButton *> *tabButtons;
|
||||
@property (nonatomic, strong) KBEmojiDataProvider *dataProvider;
|
||||
@@ -59,7 +57,7 @@
|
||||
[self addSubview:topBar];
|
||||
|
||||
self.backButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
self.backButton.titleLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
|
||||
self.backButton.titleLabel.font = [UIFont systemFontOfSize:30 weight:UIFontWeightSemibold];
|
||||
[self.backButton setTitle:@"⌨︎" forState:UIControlStateNormal];
|
||||
[self.backButton addTarget:self action:@selector(onBack) forControlEvents:UIControlEventTouchUpInside];
|
||||
[topBar addSubview:self.backButton];
|
||||
@@ -97,9 +95,9 @@
|
||||
[self.collectionView registerClass:KBEmojiCollectionCell.class forCellWithReuseIdentifier:@"KBEmojiCollectionCell"];
|
||||
[self addSubview:self.collectionView];
|
||||
|
||||
self.bottomBar = [[UIView alloc] init];
|
||||
self.bottomBar.backgroundColor = [UIColor clearColor];
|
||||
self.bottomBar = [[KBEmojiBottomBarView alloc] init];
|
||||
[self addSubview:self.bottomBar];
|
||||
[self.bottomBar.deleteButton addTarget:self action:@selector(onDelete) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
// self.searchButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
// self.searchButton.layer.cornerRadius = 20;
|
||||
@@ -109,26 +107,6 @@
|
||||
// [self.searchButton addTarget:self action:@selector(onSearch) forControlEvents:UIControlEventTouchUpInside];
|
||||
// [self.bottomBar addSubview:self.searchButton];
|
||||
|
||||
self.tabScrollView = [[UIScrollView alloc] init];
|
||||
self.tabScrollView.showsHorizontalScrollIndicator = NO;
|
||||
self.tabScrollView.backgroundColor = [UIColor clearColor];
|
||||
[self.bottomBar addSubview:self.tabScrollView];
|
||||
|
||||
self.tabStackView = [[UIStackView alloc] init];
|
||||
self.tabStackView.axis = UILayoutConstraintAxisHorizontal;
|
||||
self.tabStackView.spacing = 8;
|
||||
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);
|
||||
@@ -141,32 +119,6 @@
|
||||
make.height.mas_equalTo(40);
|
||||
}];
|
||||
|
||||
// [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
// make.right.equalTo(self.bottomBar.mas_right).offset(-16);
|
||||
// make.centerY.equalTo(self.bottomBar);
|
||||
// make.width.mas_equalTo(84);
|
||||
// make.height.mas_equalTo(40);
|
||||
// }];
|
||||
|
||||
[self.tabScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.bottomBar.mas_left).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);
|
||||
}];
|
||||
|
||||
[self.tabStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.tabScrollView);
|
||||
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];
|
||||
@@ -191,12 +143,13 @@
|
||||
btn.layer.cornerCurve = kCACornerCurveContinuous;
|
||||
}
|
||||
}
|
||||
if (self.deleteButton) {
|
||||
CGFloat radius = MIN(CGRectGetHeight(self.deleteButton.bounds), CGRectGetWidth(self.deleteButton.bounds)) / 2.0;
|
||||
UIButton *deleteButton = self.bottomBar.deleteButton;
|
||||
if (deleteButton) {
|
||||
CGFloat radius = MIN(CGRectGetHeight(deleteButton.bounds), CGRectGetWidth(deleteButton.bounds)) / 2.0;
|
||||
if (radius > 0) {
|
||||
self.deleteButton.layer.cornerRadius = radius;
|
||||
deleteButton.layer.cornerRadius = radius;
|
||||
if (@available(iOS 13.0, *)) {
|
||||
self.deleteButton.layer.cornerCurve = kCACornerCurveContinuous;
|
||||
deleteButton.layer.cornerCurve = kCACornerCurveContinuous;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,8 +185,10 @@
|
||||
}
|
||||
|
||||
- (void)rebuildTabButtons {
|
||||
for (UIView *v in self.tabStackView.arrangedSubviews) {
|
||||
[self.tabStackView removeArrangedSubview:v];
|
||||
UIStackView *stackView = self.bottomBar.tabStackView;
|
||||
if (!stackView) { return; }
|
||||
for (UIView *v in stackView.arrangedSubviews) {
|
||||
[stackView removeArrangedSubview:v];
|
||||
[v removeFromSuperview];
|
||||
}
|
||||
NSMutableArray<UIButton *> *buttons = [NSMutableArray arrayWithCapacity:self.categories.count];
|
||||
@@ -248,8 +203,8 @@
|
||||
[btn addTarget:self action:@selector(onTabTapped:) forControlEvents:UIControlEventTouchUpInside];
|
||||
btn.contentEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 12);
|
||||
btn.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
// [btn.heightAnchor constraintEqualTo:self.tabScrollView.heightAnchor].active = YES;
|
||||
[self.tabStackView addArrangedSubview:btn];
|
||||
// [btn.heightAnchor constraintEqualTo:self.bottomBar.tabScrollView.heightAnchor].active = YES;
|
||||
[stackView addArrangedSubview:btn];
|
||||
[buttons addObject:btn];
|
||||
}];
|
||||
self.tabButtons = buttons.copy;
|
||||
@@ -287,10 +242,13 @@
|
||||
|
||||
- (void)scrollTabToVisible:(NSInteger)index {
|
||||
if (index < 0 || index >= self.tabButtons.count) return;
|
||||
UIScrollView *scrollView = self.bottomBar.tabScrollView;
|
||||
UIStackView *stackView = self.bottomBar.tabStackView;
|
||||
if (!scrollView || !stackView) { return; }
|
||||
UIButton *btn = self.tabButtons[index];
|
||||
CGRect rect = [self.tabScrollView convertRect:btn.frame fromView:self.tabStackView];
|
||||
CGRect rect = [scrollView convertRect:btn.frame fromView:stackView];
|
||||
rect = CGRectInset(rect, -12, 0);
|
||||
[self.tabScrollView scrollRectToVisible:rect animated:YES];
|
||||
[scrollView scrollRectToVisible:rect animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
@@ -351,10 +309,10 @@
|
||||
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;
|
||||
if (self.bottomBar.deleteButton) {
|
||||
self.bottomBar.deleteButton.backgroundColor = self.tabNormalColor;
|
||||
UIColor *deleteTitleColor = theme.keyTextColor ?: [UIColor whiteColor];
|
||||
[self.deleteButton setTitleColor:deleteTitleColor forState:UIControlStateNormal];
|
||||
[self.bottomBar.deleteButton setTitleColor:deleteTitleColor forState:UIControlStateNormal];
|
||||
}
|
||||
if (self.magnifierView) {
|
||||
self.magnifierView.backgroundColor = theme.keyBackground ?: [UIColor colorWithWhite:1 alpha:0.9];
|
||||
|
||||
Reference in New Issue
Block a user