Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gblancogarcia committed May 17, 2015
1 parent d59ea37 commit 009b2d1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 82 deletions.
98 changes: 44 additions & 54 deletions GBInfiniteScrollView/GBInfiniteScrollView/GBInfiniteScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,58 +29,46 @@
#import "GBInfiniteScrollViewPage.h"

typedef NS_ENUM(NSInteger, GBAutoScrollDirection) {
GBAutoScrollDirectionRightToLeft, /**<
* Automatic scrolling from right to left.
* @warning Default
*/
GBAutoScrollDirectionLeftToRight, /**<
* Automatic scrolling from left to right.
*/
GBAutoScrollDirectionTopToBottom, /**<
* Automatic scrolling from top to bottom.
*/
GBAutoScrollDirectionBottomToTop /**<
* Automatic scrolling from bottom to top.
*/
/** Automatic scrolling from right to left. This is the default. */
GBAutoScrollDirectionRightToLeft,
/** Automatic scrolling from left to right. */
GBAutoScrollDirectionLeftToRight,
/** Automatic scrolling from top to bottom. */
GBAutoScrollDirectionTopToBottom,
/** Automatic scrolling from bottom to top. */
GBAutoScrollDirectionBottomToTop
};

typedef NS_ENUM(NSInteger, GBScrollDirection) {
GBScrollDirectionHorizontal, /**<
* Horizontal scroll direction.
* @warning Default
*/
GBScrollDirectionVertical /**<
* Vertical scroll direction.
*/
/** Horizontal scroll direction. */
GBScrollDirectionHorizontal,
/** Vertical scroll direction. */
GBScrollDirectionVertical
};

@interface GBInfiniteScrollViewParent : UIScrollView

/**
* Timing function of an scroll animation.
*
* Default CAMediaTimingFunctionEaseInEaseOut
* Defaults to CAMediaTimingFunctionEaseInEaseOut.
*/
@property (nonatomic) CAMediaTimingFunction *timingFunction;

/**
* The animation duration for the contentOffset
*
* Default 0.25f
* The animation duration for the contentOffset.
* Defaults to 0.25f
*/
@property (nonatomic) CGFloat animationDuration;

/**
* Debug mode.
*
* Default NO.
* Defaults to NO.
*/
@property (nonatomic, getter = isDebugModeOn) BOOL debug;

/**
* Verbose for debug mode.
*
* Default NO.
* Defaults to NO.
*/
@property (nonatomic, getter = isVerboseDebugModeOn) BOOL verboseDebug;

Expand All @@ -94,7 +82,7 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
* which allows users to scroll infinitely in the horizontal direction. GBInfiniteScrollView also provides automatic
* scrolling feature.
*
* A GBInfiniteScrollView object must have an object that acts as a data source and an object that acts as a delegate.
* A infinite scroll view object must have an object that acts as a data source and an object that acts as a delegate.
* The data source must adopt the GBInfiniteScrollViewDataSource protocol and the delegate must adopt the
* GBInfiniteScrollViewDelegate protocol. The data source provides the views that GBInfiniteScrollView needs to display.
* The delegate allows the adopting delegate to respond to scrolling operations.
Expand All @@ -108,12 +96,12 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
@interface GBInfiniteScrollView : GBInfiniteScrollViewParent <UIScrollViewDelegate>

/**
* The data source of the Infinite-scroll-view object.
* The data source of the infinite scroll view object.
*/
@property (nonatomic, assign) id <GBInfiniteScrollViewDataSource> infiniteScrollViewDataSource;

/**
* The delegate of the Infinite-scroll-view object.
* The delegate of the infinite scroll view object.
*/
@property (nonatomic, assign) id <GBInfiniteScrollViewDelegate> infiniteScrollViewDelegate;

Expand Down Expand Up @@ -202,15 +190,15 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
/**
* Gets a reusable page.
*
* @return A reusable infinite scroll view page object.
* @return A reusable GBInfiniteScrollViewPage object.
*/
- (GBInfiniteScrollViewPage *)dequeueReusablePage;

/**
* Scrolls a specific page.
*
* @param index Index of the page
* @param animated YES if the scrolling should be animated, NO if it should be immediate.
* @param index Index of the page.
* @param animated YES if the scrolling should be animated, NO if it should be immediate.
*/
- (void)scrollToPageAtIndex:(NSUInteger)index animated:(BOOL)animated;

Expand All @@ -230,9 +218,9 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
*
* @warning Required
*
* @param infiniteScrollView Infinite Scroll View Object
* @param infiniteScrollView The infinite scroll view object.
*
* @return An NSInteger with the number of pages of the Infinite Scroll View Object
* @return An NSInteger with the number of pages of the GBInfiniteScrollViewPage object.
*/
- (NSInteger)numberOfPagesInInfiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView;

Expand All @@ -241,12 +229,13 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
*
* @warning Required
*
* @param infiniteScrollView Infinite Scroll View Object
* @param index Index of the page
* @param infiniteScrollView The infinite scroll view object.
* @param index Index of the page
*
* @return The GBInfiniteScrollViewPage object for the index
* @return The GBInfiniteScrollViewPage object for the index.
*/
- (GBInfiniteScrollViewPage *)infiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView pageAtIndex:(NSUInteger)index;
- (GBInfiniteScrollViewPage *)infiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView
pageAtIndex:(NSUInteger)index;

@end

Expand All @@ -260,7 +249,7 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
@optional

/**
* Called when the GBInfiniteScrollView is panning
* Called when the GBInfiniteScrollView is panning.
*
* @warning Optional
*
Expand All @@ -274,7 +263,7 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
*
* @warning Optional
*
* @param infiniteScrollView Infinite Scroll View Object
* @param infiniteScrollView The infinite scroll view object.
*/
- (void)infiniteScrollViewDidScrollNextPage:(GBInfiniteScrollView *)infiniteScrollView;

Expand All @@ -283,17 +272,17 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
*
* @warning Optional
*
* @param infiniteScrollView Infinite Scroll View Object
* @param infiniteScrollView The infinite scroll view object.
*/
- (void)infiniteScrollViewDidScrollPreviousPage:(GBInfiniteScrollView *)infiniteScrollView;

/**
* Called when use tap on GBInfiniteScrollView
* Called when use tap on GBInfiniteScrollView.
*
* @warning Optional
*
* @param infiniteScrollView Infinite Scroll View Object
* @param pageIndex tapped page index
* @param infiniteScrollView The infinite scroll view object.
* @param pageIndex Tapped page index.
*/
- (void)infiniteScrollView:(GBInfiniteScrollView *)infiniteScrollView didTapAtIndex:(NSInteger)pageIndex;

Expand All @@ -302,7 +291,7 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
*
* @warning Optional
*
* @param infiniteScrollView Infinite Scroll View Object
* @param infiniteScrollView The infinite scroll view object.
*/
- (void)infiniteScrollViewWillBeginDragging:(GBInfiniteScrollView *)infiniteScrollView;

Expand All @@ -311,18 +300,19 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
*
* @warning Optional
*
* @param infiniteScrollView Infinite Scroll View Object
* @param velocity The velocity of the scroll view (in points) at the moment the touch was released
* @param targetContentOffset The expected offset when the scrolling action decelerates to a stop
* @param infiniteScrollView The infinite scroll view object.
* @param velocity The velocity of the scroll view (in points) at the moment the touch was released.
* @param targetContentOffset The expected offset when the scrolling action decelerates to a stop.
*/
- (void)infiniteScrollViewWillEndDragging:(GBInfiniteScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset;
- (void)infiniteScrollViewWillEndDragging:(GBInfiniteScrollView *)scrollView withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset;

/**
* Asks the delegate if it is allowed to scroll to next page.
*
* @warning Optional
*
* @param infiniteScrollView Infinite Scroll View Object
* @param infiniteScrollView The infinite scroll view object.
*/
- (BOOL)infiniteScrollViewShouldScrollNextPage:(GBInfiniteScrollView *)infiniteScrollView;

Expand All @@ -331,7 +321,7 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
*
* @warning Optional
*
* @param infiniteScrollView Infinite Scroll View Object
* @param infiniteScrollView The infinite scroll view object.
*/
- (BOOL)infiniteScrollViewShouldScrollPreviousPage:(GBInfiniteScrollView *)infiniteScrollView;

Expand Down
47 changes: 31 additions & 16 deletions GBInfiniteScrollView/GBInfiniteScrollView/GBInfiniteScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,48 @@

#import "GBInfiniteScrollView.h"

/// Constants used for Newton approximation of cubic function root.
/**
* Constants used for Newton approximation of cubic function root.
*/
const static double kApproximationTolerance = 0.00000001;
const static int kMaximumSteps = 10;

@interface GBInfiniteScrollViewParent ()

/// Display link used to trigger event to scroll the view.
/**
* Display link used to trigger event to scroll the view.
*/
@property(nonatomic) CADisplayLink *displayLink;

/// States whether the animation has started.
/**
* States whether the animation has started.
*/
@property(nonatomic) BOOL animationStarted;

/// Time at the begining of an animation.
/**
* Time at the begining of an animation.
*/
@property(nonatomic) CFTimeInterval beginTime;

/// The content offset at the begining of an animation.
/**
* The content offset at the begining of an animation.
*/
@property(nonatomic) CGPoint beginContentOffset;

/// The delta between the contentOffset at the start of the animation and
/// the contentOffset at the end of the animation.
/**
* The delta between the contentOffset at the start of the animation and the contentOffset at the end of the animation.
*/
@property(nonatomic) CGPoint deltaContentOffset;

/**
* Sets the contentOffset of the ScrollView and animates the transition.
*
* @param contentOffset A point (expressed in points) that is offset from the
* content view’s origin.
* @param contentOffset A point (expressed in points) that is offset from the content view’s origin.
*/
- (void)setContentOffsetWithCustomDuration:(CGPoint)contentOffset;

/**
* Cancel the ongoing animation
* Cancel the ongoing animation.
*/
- (void)cancelAnimation;

Expand Down Expand Up @@ -123,7 +133,8 @@ - (void)setupDefaultValuesParent
}

self.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
self.animationDuration = 0.25f; // Default setContentOffset time animation.
// Default setContentOffset time animation
self.animationDuration = 0.25f;
}

#pragma mark - Set ContentOffset with Custom Animation
Expand Down Expand Up @@ -162,6 +173,7 @@ - (void)updateContentOffset:(CADisplayLink *)displayLink

// Ratio of duration that went by
CGFloat progress = (CGFloat)(deltaTime / self.animationDuration);

if (progress < 1.0) {
// Ratio adjusted by timing function
CGFloat adjustedProgress = (CGFloat)timingFunctionValue(self.timingFunction, progress);
Expand Down Expand Up @@ -199,7 +211,7 @@ - (void)stopAnimation

if (self.delegate
&& [self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)]) {
// inform delegate about end of animation
// Inform delegate about end of animation
[self.delegate scrollViewDidEndScrollingAnimation:self];
}
}
Expand Down Expand Up @@ -233,7 +245,7 @@ CGPoint CGPointMinus(CGPoint p, CGPoint q) {
}

double cubicDerivativeValue(double a, double b, double c, double __unused d, double x) {
/// Derivation of the cubic (a*x*x*x)+(b*x*x)+(c*x)+d
// Derivation of the cubic (a*x*x*x)+(b*x*x)+(c*x)+d
return (3*a*x*x)+(2*b*x)+c;
}

Expand Down Expand Up @@ -479,13 +491,15 @@ - (void)setUpTimer
}

if (self.autoScroll) {
if (self.autoScrollDirection == GBAutoScrollDirectionLeftToRight || self.autoScrollDirection == GBAutoScrollDirectionTopToBottom) {
if (self.autoScrollDirection == GBAutoScrollDirectionLeftToRight ||
self.autoScrollDirection == GBAutoScrollDirectionTopToBottom) {
self.timer = [NSTimer scheduledTimerWithTimeInterval:self.interval
target:self
selector:@selector(scrollToPreviousPage)
userInfo:nil
repeats:YES];
} else if (self.autoScrollDirection == GBAutoScrollDirectionRightToLeft || self.autoScrollDirection == GBAutoScrollDirectionBottomToTop){
} else if (self.autoScrollDirection == GBAutoScrollDirectionRightToLeft ||
self.autoScrollDirection == GBAutoScrollDirectionBottomToTop){
self.timer = [NSTimer scheduledTimerWithTimeInterval:self.interval
target:self
selector:@selector(scrollToNextPage)
Expand Down Expand Up @@ -796,7 +810,8 @@ - (GBInfiniteScrollViewPage *)pageAtIndex:(NSUInteger)index
NSUInteger visibleIndex = [self.visibleIndices indexOfObject:[NSNumber numberWithUnsignedInteger:index]];

if ((visibleIndex == NSNotFound) || (self.needsReloadData)) {
if (self.infiniteScrollViewDataSource && [self.infiniteScrollViewDataSource respondsToSelector:@selector(infiniteScrollView:pageAtIndex:)]) {
if (self.infiniteScrollViewDataSource &&
[self.infiniteScrollViewDataSource respondsToSelector:@selector(infiniteScrollView:pageAtIndex:)]) {
page = [self.infiniteScrollViewDataSource infiniteScrollView:self pageAtIndex:index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, GBInfiniteScrollViewPageStyle) {
GBInfiniteScrollViewPageStyleCustom, /**<
* Page Style custom.
*/
GBInfiniteScrollViewPageStyleText, /**<
* Page Style Text
*/
GBInfiniteScrollViewPageStyleImage /**<
* Page Style Image
*/
/** Page Style Custom. */
GBInfiniteScrollViewPageStyleCustom,
/** Page Style Text. */
GBInfiniteScrollViewPageStyleText,
/** Page Style Image */
GBInfiniteScrollViewPageStyleImage
};

@interface GBInfiniteScrollViewPage : UIView

/**
* Initializes and returns a newly allocated view object with the specified page style.
*
* @param style GBInfiniteScrollViewPageStyle type
* @param style The GBInfiniteScrollViewPageStyle type.
*
* @return An initialized view object or nil if the object couldn't be created.
*/
Expand All @@ -36,8 +33,10 @@ typedef NS_ENUM(NSInteger, GBInfiniteScrollViewPageStyle) {
/**
* Initializes and returns a newly allocated view object with the specified frame rectangle.
*
* @param frame The frame rectangle for the view, measured in points. The origin of the frame is relative to the superview in which you plan to add it. This method uses the frame rectangle to set the center and bounds properties accordingly.
* @param style GBInfiniteScrollViewPageStyle type
* @param frame The frame rectangle for the view, measured in points. The origin of the frame is relative to the
* superview in which you plan to add it. This method uses the frame rectangle to set the center and
* bounds properties accordingly.
* @param style The GBInfiniteScrollViewPageStyle type.
*
* @return An initialized view object or nil if the object couldn't be created.
*/
Expand Down

0 comments on commit 009b2d1

Please sign in to comment.