1
This commit is contained in:
@@ -30,8 +30,7 @@
|
|||||||
|
|
||||||
// layout - Masonry
|
// layout - Masonry
|
||||||
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
make.edges.equalTo(self);
|
make.edges.equalTo(self); // 高度由外部容器决定
|
||||||
make.height.mas_equalTo(40);
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
[self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
@@ -47,6 +46,9 @@
|
|||||||
make.right.equalTo(self.searchButton.mas_left).offset(-8);
|
make.right.equalTo(self.searchButton.mas_left).offset(-8);
|
||||||
make.height.mas_equalTo(30);
|
make.height.mas_equalTo(30);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
self.bgView.layer.borderWidth = 1;
|
||||||
|
self.bgView.layer.borderColor = [UIColor colorWithHex:0xE6E6E6].CGColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Action
|
#pragma mark - Action
|
||||||
@@ -121,4 +123,3 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ typedef NS_ENUM(NSInteger, KBSearchSection) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@interface KBSearchVC ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
@interface KBSearchVC ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
||||||
// 顶部搜索栏(封装的 View)
|
// 顶部搜索栏(封装的 View)——放到导航栏的 titleView 中,Y 轴与返回按钮一致
|
||||||
@property (nonatomic, strong) KBSearchBarView *searchBarView;
|
@property (nonatomic, strong) KBSearchBarView *searchBarView;
|
||||||
|
@property (nonatomic, strong) UIView *titleContainer; // 承载 searchBarView 的容器
|
||||||
// 列表
|
// 列表
|
||||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||||
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
|
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
|
||||||
@@ -39,19 +40,14 @@ typedef NS_ENUM(NSInteger, KBSearchSection) {
|
|||||||
self.view.backgroundColor = [UIColor whiteColor];
|
self.view.backgroundColor = [UIColor whiteColor];
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
[self.view addSubview:self.searchBarView];
|
|
||||||
[self.view addSubview:self.collectionView];
|
[self.view addSubview:self.collectionView];
|
||||||
|
|
||||||
// 布局 - Masonry
|
// 将搜索栏放进导航栏 titleView,Y 轴自然与返回按钮对齐
|
||||||
[self.searchBarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
self.navigationItem.titleView = self.titleContainer;
|
||||||
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.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
[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);
|
make.left.right.bottom.equalTo(self.view);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@@ -192,6 +188,30 @@ typedef NS_ENUM(NSInteger, KBSearchSection) {
|
|||||||
return _searchBarView;
|
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 {
|
- (UICollectionViewFlowLayout *)flowLayout {
|
||||||
if (!_flowLayout) {
|
if (!_flowLayout) {
|
||||||
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
||||||
|
|||||||
Reference in New Issue
Block a user