Skip to content

Commit

Permalink
Merge pull request #1 from dimovskidamjan/hotfix/rotation-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dimovskidamjan authored Feb 24, 2017
2 parents b3d7b66 + 98b24a0 commit b826884
Showing 1 changed file with 14 additions and 1 deletion.
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

0 comments on commit b826884

Please sign in to comment.