Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0a8ec42f6d
Fetching contributors…

Cannot retrieve contributors at this time

221 lines (141 sloc) 8.238 kb
//
// CCScrollLayer.h
// CCExtensions
//
// Created by Jerrod Putman on 7/29/11.
// Copyright 2011 Tiny Tim Games. All rights reserved.
//
// Portions created by Sangwoo Im.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "cocos2d.h"
#import "CCGestureRecognizer.h"
@class CCScrollLayer;
// An enumeration to specify the permitted direction of scrolling.
typedef enum
{
CCScrollLayerDirectionHorizontal,
CCScrollLayerDirectionVertical,
CCScrollLayerDirectionBoth,
} CCScrollLayerDirection;
// Constants for good default values for the scroll layer deceleration rate.
extern const float CCScrollLayerDecelerationRateNormal; // This is the default.
extern const float CCScrollLayerDecelerationRateFast;
// A protocol that delegates can conform to to respond to scroll layer events.
@protocol CCScrollLayerDelegate <NSObject>
@optional
#pragma mark - Responding to scrolling and dragging
// Called when the scroll layer is being scrolled by the user.
- (void)scrollLayerDidScroll:(CCScrollLayer *)layer;
// Called when the scroll layer is about to begin scrolling by user input.
- (void)scrollLayerWillBeginDragging:(CCScrollLayer *)layer;
// Called when the scroll layer has been released by the user, but before a calculation has been made for whether or not the layer will need to decelerate.
// TODO: - (void)scrollLayerWillEndDragging:(CCScrollLayer *)layer withVelocity:(float)velocity targetContentOffset:(CGPoint)offset;
// Called when the scroll layer has been released by the user.
- (void)scrollLayerDidEndDragging:(CCScrollLayer *)layer willDecelerate:(BOOL)decelerate;
// Called when the scroll layer begins decelerating after user input.
- (void)scrollLayerWillBeginDecelerating:(CCScrollLayer *)layer;
// Called when the scroll layer has ended decelerating after user input.
- (void)scrollLayerDidEndDecelerating:(CCScrollLayer *)layer;
// Called to query whether or not the scroll layer should scroll to the top, generally after the user has touched the top of the screen.
// TODO: - (BOOL)scrollLayerShouldScrollToTop:(CCScrollLayer *)layer;
// Called when the scroll layer scrolls to the top, generally after the user has touched the top of the screen.
// TODO: - (void)scrollLayerDidScrollToTop:(CCScrollLayer *)layer;
#pragma mark - Managing zooming
// Called when the scroll layer is about to begin zooming by user input.
- (void)scrollLayerWillBeginZooming:(CCScrollLayer *)layer;
// Called when the scroll layer has been released by the user.
- (void)scrollLayerDidEndZooming:(CCScrollLayer *)layer atScale:(float)scale;
// Called when the scroll layer is being zoomed by the user.
- (void)scrollLayerDidZoom:(CCScrollLayer *)layer;
#pragma mark - Responding to scrolling animations
// Called when setContentOffset:animated: with YES passed to the animated parameter has finished.
- (void)scrollLayerDidEndScrollingAnimation:(CCScrollLayer *)layer;
@end
#pragma mark -
// The main scroll layer interface.
@interface CCScrollLayer : CCLayer
#pragma mark - Creating a scroll layer
// Returns a new scroll layer object.
+ (id)scrollLayerWithViewSize:(CGSize)size;
// Initializes a previously allocated scroll layer object.
- (id)initWithViewSize:(CGSize)size;
#pragma mark - Managing the display of content
// Set the content offset.
- (void)setContentOffset:(CGPoint)offset animated:(BOOL)animated;
// The offset of the content, which provides the scrolling effect of the layer. Note that left-bottom point is the origin.
@property (nonatomic, assign) CGPoint contentOffset;
// Determines the size of the visible area. Use contentSize to set the actual size of the content that will be scrolled.
@property (nonatomic, assign) CGSize viewSize;
// TODO: @property (nonatomic, assign) UIEdgeInset contentInset;
// Determines if children are clipped to the viewable region of this scroll layer. YES by default.
@property (nonatomic, assign) BOOL clipToBounds;
#pragma mark - Managing scrolling
// Determines whether or not scrolling is enabled. If NO, all touch events are ignored.
@property (nonatomic, assign) BOOL scrollEnabled;
// TODO: @property (nonatomic, assign) BOOL directionalLockEnabled
// TODO: @property (nonatomic, assign) BOOL scrollsToTop
// Scrolls the layer so that the rectangle specified is visible (if possible).
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)aniamted;
// TODO: @property (nonatomic, assign) BOOL pagingEnabled
// Determines whether the scroll layer bounces when it reaches the edge of its content.
@property (nonatomic, assign) BOOL bounces;
// Determines whether bouncing always occurs when horizontal scrolling reaches the end of the content, even if the horizontal size of the content is smaller than the view.
@property (nonatomic, assign) BOOL alwaysBounceHorizontal;
// Determines whether bouncing always occurs when vertical scrolling reaches the end of the content, even if the vertical size of the content is smaller than the view.
@property (nonatomic, assign) BOOL alwaysBounceVertical;
// The rate of scroll deceleration after the user lifts their finger. CCScrollLayerDecelerationRateNormal is the default.
@property (nonatomic, assign) float decelerationRate;
// If YES, the view is being panned.
@property (nonatomic, readonly) BOOL dragging;
// If YES, the scroll layer is decelerating after scrolling.
@property (nonatomic, assign, readonly) BOOL decelerating;
// The direction the scroll layer is allowed to scroll. CCScrollViewDirectionBoth by default.
@property (nonatomic, assign) CCScrollLayerDirection direction;
#pragma mark - Managing the scroll indicator
// TODO: All of this.
#pragma mark - Zooming and panning
// The pan gesture recognizer for this scroll view.
@property (nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer;
// The pinch gesture recognizer for this scroll view.
@property (nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer;
// TODO: - (void)zoomToRect:(CGRect)rect animated:(BOOL)animated;
// The zoom scale of the content.
@property (nonatomic, assign) float zoomScale;
// Set the zoom scale of the content
- (void)setZoomScale:(float)zoom animated:(BOOL)animated;
// Determines the maximum zoom factor of the scroll view. If minimumZoom and maximumZoom are equal, then zooming will be disabled.
@property (nonatomic, assign) float maximumZoom;
// Determines the minimum zoom factor of the scroll view. If minimumZoom and maximumZoom are equal, then zooming will be disabled.
@property (nonatomic, assign) float minimumZoom;
// If YES, the view is bouncing after being zoomed.
@property (nonatomic, assign, readonly) BOOL zoomBouncing;
// If YES, the view is being zoomed.
@property (nonatomic, readonly) BOOL zooming;
// Determines whether the scroll layer bounces during zooming when it reaches its minimum or maximum bounds.
@property (nonatomic, assign) BOOL bouncesZoom;
#pragma mark - Managing the delegate
// The delegate of the scroll layer object.
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
@property (nonatomic, weak) id<CCScrollLayerDelegate> delegate;
#else
@property (nonatomic, assign) id<CCScrollLayerDelegate> delegate;
#endif
@end
Jump to Line
Something went wrong with that request. Please try again.