Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ @interface LUNSegmentedControl() <UIScrollViewDelegate, UIGestureRecognizerDeleg
@property (nonatomic, strong) NSMutableArray <NSLayoutConstraint *> *addedConstraintsToRemove;
@property (nonatomic, assign) BOOL viewWasLayoutSubviews;
@property (nonatomic, assign) BOOL layoutDependentValuesWasUpdated;
@property (nonatomic, assign) BOOL layoutAfterScrolling;

@end

Expand Down Expand Up @@ -68,9 +69,10 @@ - (void)layoutSubviews {
[super layoutSubviews];
[self layoutIfNeeded];
self.viewWasLayoutSubviews = YES;
if (!self.layoutDependentValuesWasUpdated) {
if (!self.layoutDependentValuesWasUpdated || self.layoutAfterScrolling) {
[self updateLayoutDependentValues];
}
self.layoutAfterScrolling = YES;
}

#pragma mark - Init defaults
Expand Down Expand Up @@ -727,7 +729,10 @@ - (void)reloadData {
}
}
- (void)updateLayoutDependentValues {
int state = self.currentState;
self.currentState = 0;
self.currentState = self.statesCount-1;
self.currentState = state;
self.layoutDependentValuesWasUpdated = YES;
}

Expand Down Expand Up @@ -787,6 +792,7 @@ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
self.userInteractionEnabled = YES;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.layoutAfterScrolling = NO;
if ([self.delegate respondsToSelector:@selector(segmentedControl:didScrollWithXOffset:)]) {
[self.delegate segmentedControl:self didScrollWithXOffset:self.frame.size.width - self.scrollView.contentOffset.x - self.selectorView.frame.size.width];
}
Expand Down