Skip to content

Commit

Permalink
修复某些情况defaultSelectedIndex设置失效
Browse files Browse the repository at this point in the history
  • Loading branch information
pjx committed Oct 24, 2018
1 parent d72a6fa commit 47e2a29
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/Base/JXCategoryBaseView.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ - (void)refreshState {
CGFloat targetX = frameXOfSelectedCell - self.bounds.size.width/2.0 + selectedCellWidth/2.0;
[self.collectionView setContentOffset:CGPointMake(MAX(MIN(maxX, targetX), minX), 0) animated:NO];

if (CGRectEqualToRect(self.contentScrollView.frame, CGRectZero) && self.contentScrollView.superview != nil) {
//某些情况、系统会出现JXCategoryView先布局,contentScrollView后布局。就会导致下面指定defaultSelectedIndex失效,所以发现frame为zero时,强行触发布局。
[self.contentScrollView.superview setNeedsLayout];
[self.contentScrollView.superview layoutIfNeeded];
}
[self.contentScrollView setContentOffset:CGPointMake(self.selectedIndex*self.contentScrollView.bounds.size.width, 0) animated:NO];
}

Expand Down

0 comments on commit 47e2a29

Please sign in to comment.