Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Xcode
.DS_Store
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
01FA7D39145B5FCC00D118DB /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01FA7D38145B5FCC00D118DB /* ViewController.m */; };
01FA7D3C145B5FCC00D118DB /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01FA7D3A145B5FCC00D118DB /* ViewController.xib */; };
01FACD23166114E800B8C1A0 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 01FACD22166114E800B8C1A0 /* Default-568h@2x.png */; };
047AA37617991BAC003D398E /* TailLoadingView.m in Sources */ = {isa = PBXBuildFile; fileRef = 047AA37517991BAC003D398E /* TailLoadingView.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -36,6 +37,8 @@
01FA7D38145B5FCC00D118DB /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
01FA7D3B145B5FCC00D118DB /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
01FACD22166114E800B8C1A0 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
047AA37417991BAC003D398E /* TailLoadingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TailLoadingView.h; sourceTree = "<group>"; };
047AA37517991BAC003D398E /* TailLoadingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TailLoadingView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -55,6 +58,8 @@
019466D915B3129800B9CA30 /* SwipeView */ = {
isa = PBXGroup;
children = (
047AA37417991BAC003D398E /* TailLoadingView.h */,
047AA37517991BAC003D398E /* TailLoadingView.m */,
019466DA15B3129800B9CA30 /* SwipeView.h */,
019466DB15B3129800B9CA30 /* SwipeView.m */,
);
Expand Down Expand Up @@ -182,6 +187,7 @@
01FA7D36145B5FCC00D118DB /* AppDelegate.m in Sources */,
01FA7D39145B5FCC00D118DB /* ViewController.m in Sources */,
019466DC15B3129800B9CA30 /* SwipeView.m in Sources */,
047AA37617991BAC003D398E /* TailLoadingView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
3 changes: 3 additions & 0 deletions Examples/Basic Example/SwipeViewExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ - (void)viewDidLoad
//configure page control
_pageControl.numberOfPages = _swipeView.numberOfPages;
_pageControl.defersCurrentPageDisplay = YES;

//enable loading
[_swipeView enableLoadingView];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Expand Down
11 changes: 10 additions & 1 deletion SwipeView/SwipeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


#import <UIKit/UIKit.h>

#import "TailLoadingView.h"

typedef enum
{
Expand Down Expand Up @@ -80,6 +80,10 @@ SwipeViewAlignment;
@property (nonatomic, assign) BOOL defersItemViewLoading;
@property (nonatomic, assign, getter = isVertical) BOOL vertical;

@property (nonatomic, readwrite) BOOL loadingViewEnabled;
@property (nonatomic, readonly) BOOL isLoading;
@property (nonatomic, strong) TailLoadingView *tailLoadingView;

- (void)reloadData;
- (void)reloadItemAtIndex:(NSInteger)index;
- (void)scrollByNumberOfItems:(NSInteger)itemCount duration:(NSTimeInterval)duration;
Expand All @@ -89,6 +93,9 @@ SwipeViewAlignment;
- (NSInteger)indexOfItemView:(UIView *)view;
- (NSInteger)indexOfItemViewOrSubview:(UIView *)view;

- (void)enableLoadingView;
- (void)doneLoadingMorePageContents;

@end


Expand All @@ -114,4 +121,6 @@ SwipeViewAlignment;
- (BOOL)swipeView:(SwipeView *)swipeView shouldSelectItemAtIndex:(NSInteger)index;
- (void)swipeView:(SwipeView *)swipeView didSelectItemAtIndex:(NSInteger)index;

- (void)swipeViewLoadingMore:(SwipeView*)swipeView;

@end
82 changes: 81 additions & 1 deletion SwipeView/SwipeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#import "SwipeView.h"


@interface SwipeView () <UIScrollViewDelegate, UIGestureRecognizerDelegate>
@interface SwipeView () <UIScrollViewDelegate, UIGestureRecognizerDelegate, TailloadingDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableDictionary *itemViews;
Expand All @@ -83,6 +83,8 @@ @interface SwipeView () <UIScrollViewDelegate, UIGestureRecognizerDelegate>
@property (nonatomic, assign) CGFloat lastUpdateOffset;
@property (nonatomic, strong) NSTimer *timer;

@property (nonatomic, readwrite) BOOL isLoading;

@end


Expand Down Expand Up @@ -119,6 +121,8 @@ - (void)setUp
_scrollView.scrollsToTop = NO;
_scrollView.clipsToBounds = NO;

_loadingViewEnabled = NO;

_decelerationRate = _scrollView.decelerationRate;
_itemViews = [[NSMutableDictionary alloc] init];
_previousItemIndex = 0;
Expand Down Expand Up @@ -163,6 +167,7 @@ - (void)dealloc
[_scrollView ah_release];
[_itemViews ah_release];
[_itemViewPool ah_release];
[_tailLoadingView ah_release];
[super ah_dealloc];
}

Expand Down Expand Up @@ -923,6 +928,38 @@ - (void)loadUnloadViews
[self loadViewAtIndex:[number integerValue]];
}
}

//enable loading view
if (_loadingViewEnabled)
{
//remove loading view
if (([self currentPage] < [self numberOfPages] - 1) && _tailLoadingView)
{
[_tailLoadingView removeFromSuperview];
}

//add loading view
if ([self currentPage] == [self numberOfPages] - 1)
{
if (_tailLoadingView.superview == nil) {

if (_tailLoadingView == nil) {
if (!_vertical) {
_tailLoadingView = [[TailLoadingView alloc] initWithFrame:CGRectMake(_scrollView.contentSize.width, 0, 80, _scrollView.bounds.size.height)];
}
else{
_tailLoadingView = [[TailLoadingView alloc] initWithFrame:CGRectMake(0, _scrollView.contentSize.height, _scrollView.bounds.size.width, 60)];
[_tailLoadingView setIsVertical:_vertical];
}
_tailLoadingView.delegate = self;
}

[_scrollView addSubview:_tailLoadingView];
[_scrollView bringSubviewToFront:_tailLoadingView];
}
}
}

}
}

Expand Down Expand Up @@ -998,6 +1035,42 @@ - (void)didMoveToSuperview
}
}

#pragma mark -
#pragma mark - Tail Loading
- (void)enableLoadingView
{
_loadingViewEnabled = YES;
_wrapEnabled = NO;
}

- (void)startLoadMorePageContents
{
//here should be some real data loading
_isLoading = YES;
if ([_delegate respondsToSelector:@selector(swipeViewLoadingMore:)]) {
[_delegate swipeViewLoadingMore:self];
}
}

- (void)doneLoadingMorePageContents
{
//real data loading done
_isLoading = NO;
[_tailLoadingView tailloadingScrollViewDataSourceDidFinishedLoading:_scrollView];
}

- (void)tailloadingDidTriggerLoad:(TailLoadingView *)view
{
[self startLoadMorePageContents];
[self performSelector:@selector(doneLoadingMorePageContents) withObject:nil afterDelay:3.0];
}

- (BOOL)tailloadDataSourceIsLoading:(TailLoadingView *)view
{
return _isLoading;
}


#pragma mark -
#pragma mark Gestures and taps

Expand Down Expand Up @@ -1093,6 +1166,9 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
_previousContentOffset = _scrollView.contentOffset;
}

if(_loadingViewEnabled)
[_tailLoadingView tailloadingScrollViewDidScroll:scrollView];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
Expand All @@ -1119,6 +1195,10 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
{
[_delegate swipeViewDidEndDragging:self willDecelerate:decelerate];
}

if(_loadingViewEnabled)
[_tailLoadingView tailloadingScrollViewDidEndDragging:scrollView];

}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
Expand Down
41 changes: 41 additions & 0 deletions SwipeView/TailLoadingView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// TailLoadingView.h
// SwipeViewExample
//
// Created by B.H.Liu on 13-7-18.
//
//

#import <UIKit/UIKit.h>


typedef enum{
TailLoadingDragging = 0,
TailLoadingOngoing,
TailLoadingNormal
} LoadingViewStatus;

@class TailLoadingView;

@protocol TailloadingDelegate <NSObject>

- (void)tailloadingDidTriggerLoad:(TailLoadingView*)view;
- (BOOL)tailloadDataSourceIsLoading:(TailLoadingView*)view;

@end

@interface TailLoadingView : UIView
{
UILabel *_loadingLabel;
UIActivityIndicatorView *_activityView;
LoadingViewStatus status;
}

@property (nonatomic,assign) id <TailloadingDelegate> delegate;
@property (nonatomic,readwrite) BOOL isVertical;

- (void)tailloadingScrollViewDidScroll:(UIScrollView *)scrollView;
- (void)tailloadingScrollViewDidEndDragging:(UIScrollView *)scrollView;
- (void)tailloadingScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView;

@end
Loading