@@ -164,28 +164,17 @@ - (void)setUpSegmentControl
164164 _oldSelectedIndex = index;
165165 _shopObject.shopType = index;
166166 [_collectionView reloadData ];
167+ if (_collectionView.contentOffset .y > CGRectGetHeight (_collectionHeaderView.frame ) ) {
168+ [_collectionView setContentOffset: CGPointMake (0 , CGRectGetHeight (_collectionHeaderView.frame)) animated: NO ];
169+ }
167170
168- // [weakCarousel scrollToItemAtIndex:index animated:NO];
169171 }];
170172 _shopSegmentControl.backgroundColor = [UIColor whiteColor ];
171173 [_collectionHeaderView addSubview: _shopSegmentControl];
172174 [self .view bringSubviewToFront: _shopSegmentControl];
173175}
174176
175177
176- #pragma mark - UIScrollViewDelegate
177-
178- - (void )scrollViewDidScroll : (UIScrollView *)scrollView
179- {
180- CGFloat offsetY = scrollView.contentOffset .y + scrollView.contentInset .top ;
181- CGFloat _shopSegmentControlY = CGRectGetHeight (_collectionHeaderView.frame ) - kMySegmentControl_Height - 5 ;
182- if (offsetY > _shopSegmentControlY) {
183- _shopSegmentControl.frame = CGRectMake (0 , offsetY, kScreen_Width , kMySegmentControl_Height );
184- }else
185- {
186- _shopSegmentControl.frame = CGRectMake (0 , _shopSegmentControlY , kScreen_Width , kMySegmentControl_Height );
187- }
188- }
189178
190179#pragma mark - UICollectionViewDataSource
191180
@@ -239,6 +228,27 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
239228 [self .navigationController pushViewController: exChangeViewController animated: YES ];
240229}
241230
231+
232+ #pragma mark - UIScrollViewDelegate
233+
234+ - (void )scrollViewDidScroll : (UIScrollView *)scrollView
235+ {
236+ CGFloat offsetY = scrollView.contentOffset .y + scrollView.contentInset .top ;
237+
238+ CGFloat _shopSegmentControlY = CGRectGetHeight (_collectionHeaderView.frame ) - kMySegmentControl_Height - 5 ;
239+
240+ if (offsetY > CGRectGetHeight (_collectionHeaderView.frame )) {
241+
242+ _shopSegmentControl.frame = CGRectMake (0 , 0 , kScreen_Width , kMySegmentControl_Height );
243+ [self .view addSubview: _shopSegmentControl];
244+ }else
245+ {
246+ _shopSegmentControl.frame = CGRectMake (0 , _shopSegmentControlY , kScreen_Width , kMySegmentControl_Height );
247+ [_collectionHeaderView addSubview: _shopSegmentControl];
248+ }
249+ }
250+
251+
242252- (void )didReceiveMemoryWarning {
243253 [super didReceiveMemoryWarning ];
244254 // Dispose of any resources that can be recreated.
0 commit comments