@@ -60,14 +60,6 @@ @interface SCPageViewController () <SCPageViewControllerViewDelegate, UIScrollVi
6060@end
6161
6262@implementation SCPageViewController
63- @dynamic contentOffset;
64- @dynamic bounces;
65- @dynamic touchRefusalArea;
66- @dynamic showsScrollIndicators;
67- @dynamic minimumNumberOfTouches;
68- @dynamic maximumNumberOfTouches;
69- @dynamic scrollEnabled;
70- @dynamic decelerationRate;
7163
7264- (void )dealloc
7365{
@@ -104,6 +96,14 @@ - (void)_commonSetup
10496
10597 self.layouterContentInset = UIEdgeInsetsZero;
10698 self.layouterInterItemSpacing = 0 .0f ;
99+
100+ self.scrollView = [[SCScrollView alloc ] init ];
101+ self.scrollView .autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
102+ self.scrollView .showsVerticalScrollIndicator = NO ;
103+ self.scrollView .showsHorizontalScrollIndicator = NO ;
104+ self.scrollView .decelerationRate = UIScrollViewDecelerationRateFast;
105+ self.scrollView .delegate = self;
106+ self.scrollView .clipsToBounds = NO ;
107107}
108108
109109- (void )loadView
@@ -118,14 +118,7 @@ - (void)viewDidLoad
118118
119119 [self .view setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
120120
121- self.scrollView = [[SCScrollView alloc ] initWithFrame: self .view.bounds];
122- self.scrollView .autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
123- self.scrollView .showsVerticalScrollIndicator = NO ;
124- self.scrollView .showsHorizontalScrollIndicator = NO ;
125- self.scrollView .decelerationRate = UIScrollViewDecelerationRateFast;
126- self.scrollView .delegate = self;
127- self.scrollView .clipsToBounds = NO ;
128-
121+ [self .scrollView setFrame: self .view.bounds];
129122 [self .view addSubview: self .scrollView];
130123
131124 [self reloadData ];
@@ -167,12 +160,14 @@ - (void)setLayouter:(id<SCPageLayouterProtocol>)layouter
167160 }
168161 }];
169162
170- if (animated) {
171- [UIView animateWithDuration: self .animationDuration delay: 0 .0f options: UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations: ^{
172- [self navigateToPageAtIndex: pageIndex animated: NO completion: nil ];
173- } completion: nil ];
174- } else {
175- [self navigateToPageAtIndex: pageIndex animated: animated completion: nil ];
163+ if (!self.scrollView .isRunningAnimation ) {
164+ if (animated) {
165+ [UIView animateWithDuration: self .animationDuration delay: 0 .0f options: UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations: ^{
166+ [self navigateToPageAtIndex: pageIndex animated: NO completion: nil ];
167+ } completion: nil ];
168+ } else {
169+ [self navigateToPageAtIndex: pageIndex animated: animated completion: nil ];
170+ }
176171 }
177172}
178173
@@ -243,6 +238,8 @@ - (void)navigateToPageAtIndex:(NSUInteger)pageIndex
243238 animated : (BOOL )animated
244239 completion : (void (^)())completion
245240{
241+ NSUInteger previousCurrentPage = self.currentPage ;
242+
246243 if (pageIndex >= self.numberOfPages ) {
247244 return ;
248245 }
@@ -264,7 +261,7 @@ - (void)navigateToPageAtIndex:(NSUInteger)pageIndex
264261
265262 [self _updateNavigationContraints ];
266263
267- if (!animated && [self .delegate respondsToSelector: @selector (pageViewController:didNavigateToPageAtIndex: )]) {
264+ if (!animated && previousCurrentPage != self. currentPage && [self .delegate respondsToSelector: @selector (pageViewController:didNavigateToPageAtIndex: )]) {
268265 [self .delegate pageViewController: self didNavigateToPageAtIndex: pageIndex];
269266 }
270267
@@ -342,6 +339,11 @@ - (NSUInteger)pageIndexForViewController:(UIViewController *)viewController
342339 return pageIndex;
343340}
344341
342+ - (BOOL )visible
343+ {
344+ return self.isViewVisible ;
345+ }
346+
345347#pragma mark - Navigational Constraints
346348
347349- (void )_updateBoundsAndConstraints
@@ -626,31 +628,6 @@ - (BOOL)shouldAutomaticallyForwardAppearanceMethods
626628 return NO ;
627629}
628630
629- #pragma mark - Properties and forwarding
630-
631- - (BOOL )showsScrollIndicators
632- {
633- return [self .scrollView showsHorizontalScrollIndicator ] && [self .scrollView showsVerticalScrollIndicator ];
634- }
635-
636- - (void )setShowsScrollIndicators : (BOOL )showsScrollIndicators
637- {
638- [self .scrollView setShowsHorizontalScrollIndicator: showsScrollIndicators];
639- [self .scrollView setShowsVerticalScrollIndicator: showsScrollIndicators];
640- }
641-
642- - (id )forwardingTargetForSelector : (SEL )aSelector
643- {
644- if ([self .scrollView respondsToSelector: aSelector]) {
645- return self.scrollView ;
646- } else if ([self .scrollView.panGestureRecognizer respondsToSelector: aSelector]) {
647- return self.scrollView .panGestureRecognizer ;
648- } else {
649- [NSException raise: @" SCPageViewControllerUnrecognizedSelectorException" format: @" Unrecognized selector %@ " , NSStringFromSelector (aSelector)];
650- return nil ;
651- }
652- }
653-
654631#pragma mark - UIScrollViewDelegate
655632
656633- (void )scrollViewDidScroll : (UIScrollView *)scrollView
@@ -819,10 +796,10 @@ - (CGPoint)_nextStepOffsetForFrame:(CGRect)finalFrame withVelocity:(CGPoint)velo
819796 } else if (velocity.x > 0 .0f ) {
820797 nextStepOffset.x = (NSInteger )CGRectGetMaxX (finalFrame);
821798 } else if (velocity.y < 0 .0f ) {
822- CGFloat maxOffset = self.scrollView .contentSize .height - CGRectGetHeight (self.scrollView .bounds ) + self.layouterContentInset .top + self.layouterContentInset .bottom ;
799+ CGFloat maxOffset = MAX ( self.scrollView .contentSize .height , CGRectGetHeight (self. scrollView . bounds )) - CGRectGetHeight (self.scrollView .bounds ) + self.layouterContentInset .top + self.layouterContentInset .bottom ;
823800 nextStepOffset.y = MIN (maxOffset, (NSInteger )CGRectGetMinY (finalFrame));
824801 } else if (velocity.x < 0 .0f ) {
825- CGFloat maxOffset = self.scrollView .contentSize .width - CGRectGetWidth (self.scrollView .bounds ) + self.layouterContentInset .left + self.layouterContentInset .right ;
802+ CGFloat maxOffset = MAX ( self.scrollView .contentSize .width , CGRectGetWidth (self. scrollView . bounds )) - CGRectGetWidth (self.scrollView .bounds ) + self.layouterContentInset .left + self.layouterContentInset .right ;
826803 nextStepOffset.x = MIN (maxOffset, (NSInteger )CGRectGetMinX (finalFrame));
827804 }
828805
0 commit comments