Skip to content

Commit

Permalink
added option to drag left/right folds from the edge of the screen, bu…
Browse files Browse the repository at this point in the history
…t ignores any horizontal panning gestures in the middle. disabled by default
  • Loading branch information
honcheng committed Nov 23, 2012
1 parent 2aad944 commit 6fd828a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions PaperFold/PaperFold/DemoRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ - (id)init

#warning disabling scroll, requires tapping cell twice to select cells. to be fixed
[_centerTableView setScrollEnabled:NO];
//[_paperFoldView setEnableHorizontalEdgeDragging:YES];
}
return self;
}
Expand Down
1 change: 1 addition & 0 deletions PaperFold/PaperFold/PaperFold/PaperFoldConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define kRightViewUnfoldThreshold 0.3
#define kTopViewUnfoldThreshold 0.3
#define kBottomViewUnfoldThreshold 0.3
#define kEdgeScrollWidth 35.0

typedef enum
{
Expand Down
3 changes: 2 additions & 1 deletion PaperFold/PaperFold/PaperFold/PaperFoldView.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef void (^CompletionBlock)();
- (void)paperFoldView:(id)paperFoldView viewDidOffset:(CGPoint)offset;
@end

@interface PaperFoldView : UIView <MultiFoldViewDelegate>
@interface PaperFoldView : UIView <MultiFoldViewDelegate, UIGestureRecognizerDelegate>

// main content view
@property (nonatomic, strong) TouchThroughUIView *contentView;
Expand All @@ -68,6 +68,7 @@ typedef void (^CompletionBlock)();
@property (nonatomic, assign) PaperFoldState state, lastState;
// enable and disable dragging
@property (nonatomic, assign) BOOL enableLeftFoldDragging, enableRightFoldDragging, enableTopFoldDragging, enableBottomFoldDragging;
@property (nonatomic, assign) BOOL enableHorizontalEdgeDragging;
// indicate if the fold was triggered by finger panning, or set state
@property (nonatomic, assign) BOOL isAutomatedFolding;
@property (nonatomic, assign) id<PaperFoldViewDelegate> delegate;
Expand Down
21 changes: 18 additions & 3 deletions PaperFold/PaperFold/PaperFold/PaperFoldView.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ - (void)initialize

UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onContentViewPanned:)];
[_contentView addGestureRecognizer:panGestureRecognizer];
[panGestureRecognizer setDelegate:self];

_state = PaperFoldStateDefault;
_lastState = _state;
Expand All @@ -84,6 +85,12 @@ - (void)initialize
_enableTopFoldDragging = NO;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.enableHorizontalEdgeDragging) return YES;
else return NO;
}

- (void)setCenterContentView:(UIView*)view
{
[view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
Expand Down Expand Up @@ -188,15 +195,24 @@ - (void)onContentViewPanned:(UIPanGestureRecognizer*)gesture
{
// cancel gesture if another animation has not finished yet
if ([self.animationTimer isValid]) return;

if ([gesture state]==UIGestureRecognizerStateBegan)
{
CGPoint velocity = [gesture velocityInView:self];
if ( abs(velocity.x) > abs(velocity.y))
{
if (self.state==PaperFoldStateDefault)
{
self.paperFoldInitialPanDirection = PaperFoldInitialPanDirectionHorizontal;
if (self.enableHorizontalEdgeDragging)
{
CGPoint location = [gesture locationInView:self.contentView];
if (location.x < kEdgeScrollWidth || location.x > (self.contentView.frame.size.width-kEdgeScrollWidth))
{
self.paperFoldInitialPanDirection = PaperFoldInitialPanDirectionHorizontal;
}
else self.paperFoldInitialPanDirection = PaperFoldInitialPanDirectionVertical;
}
else self.paperFoldInitialPanDirection = PaperFoldInitialPanDirectionHorizontal;
}
}
else
Expand Down Expand Up @@ -312,7 +328,6 @@ - (void)onContentViewPannedHorizontally:(UIPanGestureRecognizer*)gesture
CGPoint adjustedPoint = CGPointMake(point.x - self.rightFoldView.frame.size.width, point.y);
[self animateWithContentOffset:adjustedPoint panned:YES];
}

}
else if ([gesture state]==UIGestureRecognizerStateEnded || [gesture state]==UIGestureRecognizerStateCancelled)
{
Expand Down

0 comments on commit 6fd828a

Please sign in to comment.