Skip to content

Commit 05112fb

Browse files
committed
Attempts to resolve rotation issue (#1) which was not handled previously.
Requires view controller to forward rotation callbacks to the paging view (as shown in the demo). Each rotation is a reload of the paging view, causing its view to be recycled and cause weird animation on rotation. Will try to solve it sometimes in the future.
1 parent d678d9e commit 05112fb

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

LXPagingViews/PagingView.h

+3
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@
4343

4444
- (void)setSelectedPageIndex:(NSUInteger)theSelectedPageIndex animated:(BOOL)theAnimated;
4545

46+
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)theToInterfaceOrientation duration:(NSTimeInterval)theDuration;
47+
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)theInterfaceOrientation duration:(NSTimeInterval)theDuration;
48+
4649
@end

LXPagingViews/PagingView.m

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ @interface PagingView ()
1818
@property (nonatomic, assign) NSUInteger numberOfItems;
1919
@property (nonatomic, strong) NSMutableArray *visibleReusableViews;
2020
@property (nonatomic, assign, getter = isReferencingSuperview) BOOL referencingSuperview;
21+
@property (nonatomic, assign) NSUInteger selectedPageIndexBeforeRotation;
2122

2223
- (void)layoutSubviewsFromIndex:(NSUInteger)theFromIndex toIndex:(NSUInteger)theToIndex;
2324

@@ -33,6 +34,7 @@ @implementation PagingView
3334
@synthesize numberOfItems = _numberOfItems;
3435
@synthesize visibleReusableViews = _visibleReusableViews;
3536
@synthesize referencingSuperview = _referencingSuperview;
37+
@synthesize selectedPageIndexBeforeRotation = _selectedPageIndexBeforeRotation;
3638

3739
- (id<PagingViewDelegate>)delegate {
3840
return (id<PagingViewDelegate>)[super delegate];
@@ -288,4 +290,18 @@ - (void)observeValueForKeyPath:(NSString *)theKeyPath ofObject:(id)theObject cha
288290
}
289291
}
290292

293+
#pragma mark - Rotation methods
294+
295+
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)theToInterfaceOrientation duration:(NSTimeInterval)theDuration {
296+
self.selectedPageIndexBeforeRotation = self.selectedPageIndex;
297+
}
298+
299+
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)theInterfaceOrientation duration:(NSTimeInterval)theDuration {
300+
self.needsReloadData = YES;
301+
[self setNeedsLayout];
302+
[self layoutIfNeeded];
303+
self.selectedPageIndex = self.selectedPageIndexBeforeRotation;
304+
self.selectedPageIndexBeforeRotation = 0;
305+
}
306+
291307
@end

LXPagingViewsDemo/PagingViewController.m

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
6565
return (interfaceOrientation == UIInterfaceOrientationPortrait);
6666
}
6767

68+
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)theToInterfaceOrientation duration:(NSTimeInterval)theDuration {
69+
[self.pagingView willAnimateRotationToInterfaceOrientation:theToInterfaceOrientation duration:theDuration];
70+
}
71+
72+
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)theToInterfaceOrientation duration:(NSTimeInterval)theDuration {
73+
[self.pagingView willRotateToInterfaceOrientation:theToInterfaceOrientation duration:theDuration];
74+
}
75+
6876
#pragma mark - PagingViewDelegate methods
6977

7078
- (NSInteger)numberOfItemsInPagingView:(PagingView *)thePagingView {

LXPagingViewsDemo/PeepingPagingViewController.m

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
6464
return (interfaceOrientation == UIInterfaceOrientationPortrait);
6565
}
6666

67+
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)theToInterfaceOrientation duration:(NSTimeInterval)theDuration {
68+
[self.peepingPagingView.pagingView willAnimateRotationToInterfaceOrientation:theToInterfaceOrientation duration:theDuration];
69+
}
70+
71+
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)theToInterfaceOrientation duration:(NSTimeInterval)theDuration {
72+
[self.peepingPagingView.pagingView willRotateToInterfaceOrientation:theToInterfaceOrientation duration:theDuration];
73+
}
74+
6775
#pragma mark - PagingViewDelegate methods
6876

6977
- (NSInteger)numberOfItemsInPagingView:(PagingView *)thePagingView {

0 commit comments

Comments
 (0)