diff --git a/Example-Swift/MXPagerView-Swift.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/MXPagerView-Swift.xcscheme b/Example-Swift/MXPagerView-Swift.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/MXPagerView-Swift.xcscheme new file mode 100644 index 0000000..6247792 --- /dev/null +++ b/Example-Swift/MXPagerView-Swift.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/MXPagerView-Swift.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example-Swift/MXPagerView-Swift.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/xcschememanagement.plist b/Example-Swift/MXPagerView-Swift.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..34ca387 --- /dev/null +++ b/Example-Swift/MXPagerView-Swift.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + MXPagerView-Swift.xcscheme + + orderHint + 1 + + + SuppressBuildableAutocreation + + D03882F31BF0C704000F6400 + + primary + + + + + diff --git a/Example-Swift/MXPagerView-Swift.xcworkspace/xcuserdata/arvindhsukumar.xcuserdatad/UserInterfaceState.xcuserstate b/Example-Swift/MXPagerView-Swift.xcworkspace/xcuserdata/arvindhsukumar.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..ecbbf8d Binary files /dev/null and b/Example-Swift/MXPagerView-Swift.xcworkspace/xcuserdata/arvindhsukumar.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Example-Swift/Pods/Pods.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/Pods-MXPagerView-Swift.xcscheme b/Example-Swift/Pods/Pods.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/Pods-MXPagerView-Swift.xcscheme new file mode 100644 index 0000000..b87f136 --- /dev/null +++ b/Example-Swift/Pods/Pods.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/Pods-MXPagerView-Swift.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example-Swift/Pods/Pods.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/xcschememanagement.plist b/Example-Swift/Pods/Pods.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..4dd1082 --- /dev/null +++ b/Example-Swift/Pods/Pods.xcodeproj/xcuserdata/arvindhsukumar.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,32 @@ + + + + + SchemeUserState + + MXPagerView.xcscheme_^#shared#^_ + + orderHint + 0 + + Pods-MXPagerView-Swift.xcscheme + + orderHint + 2 + + + SuppressBuildableAutocreation + + 1076019CFB4A5F07BF71E20281D7BA1F + + primary + + + D079D9AA985DDABC43ED482FC2FB3E00 + + primary + + + + + diff --git a/MXPagerView/MXPagerView.h b/MXPagerView/MXPagerView.h index f3d59f6..64ab135 100644 --- a/MXPagerView/MXPagerView.h +++ b/MXPagerView/MXPagerView.h @@ -155,6 +155,12 @@ typedef NS_ENUM(NSInteger, MXPagerViewTransitionStyle) { */ @property (nonatomic, readonly) CGFloat progress; +/** + Determine if pages should be lazily loaded + */ +@property(assign) BOOL shouldLazyLoad; + + /** Reloads everything from scratch. redisplays pages. */ diff --git a/MXPagerView/MXPagerView.m b/MXPagerView/MXPagerView.m index 33f23ed..6ad23f0 100644 --- a/MXPagerView/MXPagerView.m +++ b/MXPagerView/MXPagerView.m @@ -33,9 +33,11 @@ @interface MXPagerView () @property (nonatomic, strong) NSMutableDictionary *registration; @property (nonatomic, strong) NSMutableArray *reuseQueue; + @end @implementation MXPagerView { + CGFloat _index; NSInteger _count; @@ -114,8 +116,16 @@ - (void)reloadData { //Updates index and loads the current selected page if ( (_count = [self.dataSource numberOfPagesInPagerView:self]) > 0) { - _index = MIN(_index, _count - 1); - [self loadPageAtIndex:_index]; + if (self.shouldLazyLoad) { + if (_index >= _count) + _index = _count-1; + + [self loadPageAtIndex:_index]; + } + else { + [self loadAllPages]; + } + [self setNeedsLayout]; } } @@ -237,7 +247,7 @@ - (void)didMovePageToIndex:(NSInteger)index { [self.delegate pagerView:self didMoveToPage:page atIndex:index]; } - //The page did change, now unload hidden pages + //The page did change, now unload hidden pages [self unLoadHiddenPages]; } @@ -271,13 +281,22 @@ - (void)loadPageAtIndex:(NSInteger)index { loadPage(index); //In case of slide behavior, its loads the neighbors as well. - if (self.transitionStyle == MXPagerViewTransitionStyleScroll) { + if (self.transitionStyle == MXPagerViewTransitionStyleScroll && self.shouldLazyLoad) { loadPage(index - 1); loadPage(index + 1); } } +- (void) loadAllPages { + for (int i = 0; i < _count; i++) { + [self loadPageAtIndex:i]; + } +} + - (void)unLoadHiddenPages { + if (!self.shouldLazyLoad) { + return; + } NSMutableArray *toUnLoad = [NSMutableArray array];