diff --git a/SwipeView/SwipeView.m b/SwipeView/SwipeView.m index 04e942b..238233b 100755 --- a/SwipeView/SwipeView.m +++ b/SwipeView/SwipeView.m @@ -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(_scrollView.contentOffset.x, _currentItemIndex * _itemSize.height); + } else { + newContentOffset = CGPointMake(_currentItemIndex * _itemSize.width, _scrollView.contentOffset.y); + } + [self setContentOffsetWithoutEvent:newContentOffset]; _scrollView.contentSize = contentSize; } }