@@ -18,6 +18,7 @@ @interface AMainViewController () <UISearchBarDelegate, ACollectionViewDelegates
1818@property (nonatomic , strong ) UILabel *noDataLabel;
1919@property (nonatomic , strong ) ACollectionView *collectionView;
2020@property (nonatomic , strong ) ACollectionViewDataHandle *collectionViewDataHandle;
21+ @property (nonatomic , assign ) CGRect keyboardFrame;
2122
2223@end
2324
@@ -34,6 +35,11 @@ - (instancetype) initWithLoader:(AInstructionLoader *)loader {
3435 selector: @selector (_loaderNotification: )
3536 name: AInstructionLoaderFinishedNotificaton
3637 object: nil ];
38+
39+ [NSNotificationCenter .defaultCenter addObserver: self
40+ selector: @selector (_keyboardWillChangeFrameNotification: )
41+ name: UIKeyboardWillChangeFrameNotification
42+ object: nil ];
3743 }
3844
3945 return self;
@@ -47,10 +53,10 @@ - (void) viewDidLoad {
4753
4854 // Serach
4955 [self .view addSubview: self .searchBar];
50-
56+
5157 // No data
5258 [self .view addSubview: self .noDataLabel];
53-
59+
5460 // Collection View
5561 [self .view addSubview: self .collectionView];
5662}
@@ -69,9 +75,13 @@ - (void) viewWillLayoutSubviews {
6975
7076 // Collection view
7177 CGFloat padding = (!leftRightInset ? 8 .0f : 0 .0f );
72- CGFloat colletionViewHeight = self.view .bounds .size .height - (CGRectGetMaxY (self.searchBar .frame ) + 5 .0f );
73- CGFloat collectionViewWidth = self.view .bounds .size .width - (leftRightInset + (padding * 2 .0f ));
74- self.collectionView .frame = CGRectMake (self.view .safeAreaInsets .left + padding, CGRectGetMaxY (self.searchBar .frame ) + 5 .0f , collectionViewWidth, colletionViewHeight);
78+ CGRect collectionViewFrame = CGRectMake (self.view .safeAreaInsets .left + padding,
79+ CGRectGetMaxY (self.searchBar .frame ) + 5 .0f ,
80+ self.view .bounds .size .width - (leftRightInset + (padding * 2 .0f )),
81+ self.view .bounds .size .height - (CGRectGetMaxY (self.searchBar .frame ) + 5 .0f ));
82+ if (self.searchBar .isFirstResponder ) collectionViewFrame.size .height -= self.keyboardFrame .size .height ;
83+
84+ self.collectionView .frame = collectionViewFrame;
7585 [self .collectionView.collectionViewLayout invalidateLayout ];
7686}
7787
@@ -94,6 +104,12 @@ - (void) _showNoDataStyle:(BOOL)show {
94104 self.collectionView .alpha = (show ? 0 .0f : 1 .0f );
95105}
96106
107+ - (void ) _keyboardWillChangeFrameNotification : (NSNotification *)notification {
108+ self.keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue ];
109+
110+ [self .view setNeedsLayout ];
111+ }
112+
97113#pragma mark - Lazy
98114
99115- (UISearchBar *) searchBar {
0 commit comments