This commit is contained in:
2025-11-08 11:48:06 +08:00
parent 9a39c29e88
commit faeb930fe3
2 changed files with 34 additions and 13 deletions

View File

@@ -30,8 +30,7 @@
// layout - Masonry
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
make.height.mas_equalTo(40);
make.edges.equalTo(self); //
}];
[self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -47,6 +46,9 @@
make.right.equalTo(self.searchButton.mas_left).offset(-8);
make.height.mas_equalTo(30);
}];
self.bgView.layer.borderWidth = 1;
self.bgView.layer.borderColor = [UIColor colorWithHex:0xE6E6E6].CGColor;
}
#pragma mark - Action
@@ -121,4 +123,3 @@
}
@end

View File

@@ -21,8 +21,9 @@ typedef NS_ENUM(NSInteger, KBSearchSection) {
};
@interface KBSearchVC ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
// View
// View titleView Y
@property (nonatomic, strong) KBSearchBarView *searchBarView;
@property (nonatomic, strong) UIView *titleContainer; // searchBarView
//
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
@@ -39,19 +40,14 @@ typedef NS_ENUM(NSInteger, KBSearchSection) {
self.view.backgroundColor = [UIColor whiteColor];
// UI
[self.view addSubview:self.searchBarView];
[self.view addSubview:self.collectionView];
// - Masonry
[self.searchBarView mas_makeConstraints:^(MASConstraintMaker *make) {
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);
}];
// titleViewY
self.navigationItem.titleView = self.titleContainer;
// - Masonry
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.searchBarView.mas_bottom).offset(12);
make.top.equalTo(self.view.mas_top).offset(KB_NAV_TOTAL_HEIGHT + 8);
make.left.right.bottom.equalTo(self.view);
}];
@@ -192,6 +188,30 @@ typedef NS_ENUM(NSInteger, KBSearchSection) {
return _searchBarView;
}
- (UIView *)titleContainer {
if (!_titleContainer) {
// 315 36 Y titleView
CGFloat width = KBFit(315.0);
_titleContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 36.0)];
_titleContainer.backgroundColor = [UIColor clearColor];
// 使 AutoLayout 315x36
_titleContainer.translatesAutoresizingMaskIntoConstraints = NO;
[[_titleContainer.widthAnchor constraintEqualToConstant:width] setActive:YES];
[[_titleContainer.heightAnchor constraintEqualToConstant:36.0] setActive:YES];
[_titleContainer setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_titleContainer setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
// searchBarView
[_titleContainer addSubview:self.searchBarView];
[self.searchBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(_titleContainer);
make.height.mas_equalTo(36.0);
}];
}
return _titleContainer;
}
- (UICollectionViewFlowLayout *)flowLayout {
if (!_flowLayout) {
_flowLayout = [[UICollectionViewFlowLayout alloc] init];