This commit is contained in:
2025-11-08 20:49:05 +08:00
parent 3b0beb52da
commit a729396401
2 changed files with 135 additions and 44 deletions

View File

@@ -2,11 +2,6 @@
// KBSearchResultVC.m
// keyBoard
//
// KBSearchBarView UICollectionView
// - Masonry
// -
// -
//
#import "KBSearchResultVC.h"
#import "KBSearchBarView.h"
@@ -16,7 +11,9 @@ static NSString * const kResultCellId = @"KBSkinCardCell";
@interface KBSearchResultVC ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
// KBSearchBarView
// +
@property (nonatomic, strong) UIView *topBar;
@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) KBSearchBarView *searchBarView;
//
@@ -35,20 +32,32 @@ static NSString * const kResultCellId = @"KBSkinCardCell";
self.view.backgroundColor = [UIColor whiteColor];
//
[self.view addSubview:self.searchBarView];
[self.view addSubview:self.topBar];
[self.topBar addSubview:self.backButton];
[self.topBar addSubview:self.searchBarView];
[self.view addSubview:self.collectionView];
// Masonry
[self.searchBarView mas_makeConstraints:^(MASConstraintMaker *make) {
// 16 40
make.top.equalTo(self.view.mas_top).offset(KB_NAV_TOTAL_HEIGHT + 8);
make.left.equalTo(self.view).offset(16);
make.right.equalTo(self.view).offset(-16);
make.height.mas_equalTo(40);
// Masonry
[self.topBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).offset(KB_STATUSBAR_HEIGHT + 8);
make.left.right.equalTo(self.view);
make.height.mas_equalTo(44);
}];
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.topBar).offset(12);
make.centerY.equalTo(self.topBar);
make.width.mas_equalTo(28);
make.height.mas_equalTo(36);
}];
[self.searchBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.backButton);
make.left.equalTo(self.backButton.mas_right).offset(12);
make.width.mas_equalTo(315);
make.height.mas_equalTo(36);
make.right.lessThanOrEqualTo(self.topBar).offset(-16);
}];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.searchBarView.mas_bottom).offset(12);
make.top.equalTo(self.topBar.mas_bottom).offset(12);
make.left.right.bottom.equalTo(self.view);
}];
@@ -62,6 +71,19 @@ static NSString * const kResultCellId = @"KBSkinCardCell";
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (self.isMovingFromParentViewController || self.isBeingDismissed) {
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
}
#pragma mark - Private
///
@@ -138,6 +160,35 @@ static NSString * const kResultCellId = @"KBSkinCardCell";
return _searchBarView;
}
- (UIView *)topBar {
if (!_topBar) {
_topBar = [[UIView alloc] init];
_topBar.backgroundColor = [UIColor whiteColor];
}
return _topBar;
}
- (UIButton *)backButton {
if (!_backButton) {
_backButton = [UIButton buttonWithType:UIButtonTypeSystem];
UIImage *img = nil;
if (@available(iOS 13.0, *)) {
img = [UIImage systemImageNamed:@"chevron.left"];
}
if (img) {
[_backButton setImage:img forState:UIControlStateNormal];
} else {
[_backButton setTitle:@"<" forState:UIControlStateNormal];
_backButton.titleLabel.font = [UIFont systemFontOfSize:22 weight:UIFontWeightSemibold];
}
[_backButton setTintColor:[UIColor blackColor]];
[_backButton addTarget:self action:@selector(onTapBack) forControlEvents:UIControlEventTouchUpInside];
}
return _backButton;
}
- (void)onTapBack { [self.navigationController popViewControllerAnimated:YES]; }
- (UICollectionViewFlowLayout *)flowLayout {
if (!_flowLayout) {
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
@@ -166,4 +217,3 @@ static NSString * const kResultCellId = @"KBSkinCardCell";
}
@end