From c8b7a94b6d0cbdf93a8d9bc2457edbf158bd418c Mon Sep 17 00:00:00 2001 From: Kun Chen Date: Mon, 1 Aug 2016 22:18:48 -0700 Subject: [PATCH] Fix the issue that current item index may be changed after rotation --- SwipeView/SwipeView.m | 8 ++++++++ 1 file changed, 8 insertions(+) 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; } }