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
15 changes: 14 additions & 1 deletion SwipeView/SwipeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@ - (void)updateScrollViewDimensions

if (!CGSizeEqualToSize(_scrollView.contentSize, contentSize))
{
// contentSize is changed, make sure the content offset is adjusted based on the current item index
CGPoint newContentOffset;
if (_vertical) {
newContentOffset = CGPointMake(0.f, _currentItemIndex * _itemSize.height);
} else {
newContentOffset = CGPointMake(_currentItemIndex * _itemSize.width, 0.f);
}
[self setContentOffsetWithoutEvent:newContentOffset];
_scrollView.contentSize = contentSize;
}
}
Expand Down Expand Up @@ -724,11 +732,14 @@ - (void)setContentOffsetWithoutEvent:(CGPoint)contentOffset
{
if (!CGPointEqualToPoint(_scrollView.contentOffset, contentOffset))
{
BOOL old = _suppressScrollEvent;

BOOL animationEnabled = [UIView areAnimationsEnabled];
if (animationEnabled) [UIView setAnimationsEnabled:NO];
_suppressScrollEvent = YES;
_scrollView.contentOffset = contentOffset;
_suppressScrollEvent = NO;
_suppressScrollEvent = old;
if (animationEnabled) [UIView setAnimationsEnabled:YES];
}
}
Expand Down Expand Up @@ -1000,7 +1011,7 @@ - (void)reloadData

//get number of items
[self updateItemSizeAndCount];

//layout views
[self setNeedsLayout];

Expand Down Expand Up @@ -1158,6 +1169,7 @@ - (void)scrollViewDidScroll:(__unused UIScrollView *)scrollView

- (void)scrollViewWillBeginDragging:(__unused UIScrollView *)scrollView
{
_suppressScrollEvent = NO;
[_delegate swipeViewWillBeginDragging:self];

//force refresh
Expand Down Expand Up @@ -1195,6 +1207,7 @@ - (void)scrollViewDidEndDecelerating:(__unused UIScrollView *)scrollView
[self didScroll];

[_delegate swipeViewDidEndDecelerating:self];
_suppressScrollEvent = YES;
}

@end