From bbd5cfe90176829431d339505fa5512278a5a1ca Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Wed, 7 Nov 2012 18:30:18 +1100 Subject: [PATCH 01/17] Disable the gesture recogniser when dragging in both directions is disabled This is needed to have the content view's regular gesture recognisers not being cancelled, e.g., when using a reorder control. --- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 118bbc9..6457743 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -38,6 +38,7 @@ @interface PaperFoldView () @property (nonatomic, copy) CompletionBlock completionBlock; +@property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer; @end @@ -73,13 +74,13 @@ - (void)initialize [_contentView setBackgroundColor:[UIColor whiteColor]]; [_contentView setAutoresizesSubviews:YES]; - UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onContentViewPanned:)]; - [_contentView addGestureRecognizer:panGestureRecognizer]; + self.panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onContentViewPanned:)]; + [_contentView addGestureRecognizer:self.panGestureRecognizer]; _state = PaperFoldStateDefault; _lastState = _state; - _enableRightFoldDragging = YES; - _enableLeftFoldDragging = YES; + _enableRightFoldDragging = NO; + _enableLeftFoldDragging = NO; } - (void)setCenterContentView:(UIView*)view @@ -103,6 +104,8 @@ - (void)setLeftFoldContentView:(UIView*)view [line setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; [self.contentView addSubview:line]; [line setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:0.5]]; + + self.enableLeftFoldDragging = YES; } - (void)setRightFoldContentView:(UIView*)view rightViewFoldCount:(int)rightViewFoldCount rightViewPullFactor:(float)rightViewPullFactor @@ -119,8 +122,25 @@ - (void)setRightFoldContentView:(UIView*)view rightViewFoldCount:(int)rightViewF [self.contentView addSubview:line]; [line setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight]; [line setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:0.5]]; + + self.enableRightFoldDragging = YES; +} + +- (void)setEnableLeftFoldDragging:(BOOL)enableLeftFoldDragging +{ + _enableLeftFoldDragging = enableLeftFoldDragging; + + self.panGestureRecognizer.enabled = self.enableLeftFoldDragging || self.enableRightFoldDragging; } +- (void)setEnableRightFoldDragging:(BOOL)enableRightFoldDragging +{ + _enableRightFoldDragging = enableRightFoldDragging; + + self.panGestureRecognizer.enabled = self.enableLeftFoldDragging || self.enableRightFoldDragging; +} + + - (void)onContentViewPanned:(UIPanGestureRecognizer*)gesture { // cancel gesture if another animation has not finished yet From ea12fc0afcdc40ff27d4e9f83a43c3be5a642f82 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Thu, 8 Nov 2012 17:05:36 +1100 Subject: [PATCH 02/17] Only show the divider line when folding --- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 114 ++++++++++++------ 1 file changed, 75 insertions(+), 39 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 6457743..eee64ad 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -37,9 +37,15 @@ @interface PaperFoldView () +@property (nonatomic, weak) UIView *leftDividerLine; +@property (nonatomic, weak) UIView *rightDividerLine; + @property (nonatomic, copy) CompletionBlock completionBlock; @property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer; +// indicate if the divider line should be visible +@property (nonatomic, assign) BOOL showDividerLines; + @end @implementation PaperFoldView @@ -77,6 +83,7 @@ - (void)initialize self.panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onContentViewPanned:)]; [_contentView addGestureRecognizer:self.panGestureRecognizer]; + _showDividerLines = NO; _state = PaperFoldStateDefault; _lastState = _state; _enableRightFoldDragging = NO; @@ -98,30 +105,34 @@ - (void)setLeftFoldContentView:(UIView*)view [self insertSubview:self.leftFoldView belowSubview:self.contentView]; [self.leftFoldView setContent:view]; [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; - [self setPaperFoldState:PaperFoldStateDefault]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(-1,0,1,self.frame.size.height)]; [line setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; [self.contentView addSubview:line]; [line setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:0.5]]; + line.alpha = 0; + self.leftDividerLine = line; self.enableLeftFoldDragging = YES; } -- (void)setRightFoldContentView:(UIView*)view rightViewFoldCount:(int)rightViewFoldCount rightViewPullFactor:(float)rightViewPullFactor +- (void)setRightFoldContentView:(UIView*)view + rightViewFoldCount:(int)rightViewFoldCount + rightViewPullFactor:(float)rightViewPullFactor { self.rightFoldView = [[MultiFoldView alloc] initWithFrame:CGRectMake(self.frame.size.width,0,view.frame.size.width,self.frame.size.height) folds:rightViewFoldCount pullFactor:rightViewPullFactor]; [self.rightFoldView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight]; [self.contentView insertSubview:self.rightFoldView atIndex:0]; [self.rightFoldView setContent:view]; [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; - [self setPaperFoldState:PaperFoldStateDefault]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width,0,1,self.frame.size.height)]; [line setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; [self.contentView addSubview:line]; [line setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight]; [line setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:0.5]]; + line.alpha = 0; + self.rightDividerLine = line; self.enableRightFoldDragging = YES; } @@ -145,11 +156,14 @@ - (void)onContentViewPanned:(UIPanGestureRecognizer*)gesture { // cancel gesture if another animation has not finished yet if ([self.animationTimer isValid]) return; - + CGPoint point = [gesture translationInView:self]; if ([gesture state]==UIGestureRecognizerStateChanged) { + // show the divider while dragging + [self setShowDividerLines:YES animated:YES]; + if (_state==PaperFoldStateDefault) { // animate folding when panned @@ -169,6 +183,9 @@ - (void)onContentViewPanned:(UIPanGestureRecognizer*)gesture } else if ([gesture state]==UIGestureRecognizerStateEnded || [gesture state]==UIGestureRecognizerStateCancelled) { + // hide the divider once we are done + [self setShowDividerLines:NO animated:YES]; + float x = point.x; if (x>=0.0) // offset to the right { @@ -217,15 +234,9 @@ - (void)animateWithContentOffset:(CGPoint)point panned:(BOOL)panned // set the limit of the right offset if (x>=self.leftFoldView.frame.size.width) { - if (self.lastState!=PaperFoldStateLeftUnfolded) { - if (self.completionBlock != nil) { - self.completionBlock(); - self.completionBlock = nil; - } else if ([self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateLeftUnfolded]; - [self setIsAutomatedFolding:NO]; - } + if (self.lastState != PaperFoldStateLeftUnfolded) { + [self finishForState:PaperFoldStateLeftUnfolded]; + [self setIsAutomatedFolding:NO]; } self.lastState = self.state; self.state = PaperFoldStateLeftUnfolded; @@ -249,15 +260,8 @@ - (void)animateWithContentOffset:(CGPoint)point panned:(BOOL)panned float x1 = x; if (x1<=-self.rightFoldView.frame.size.width) { - if (self.lastState!=PaperFoldStateRightUnfolded) { - if (self.completionBlock != nil) { - self.completionBlock(); - self.completionBlock = nil; - } else if ([self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateRightUnfolded]; - [self setIsAutomatedFolding:NO]; - } + if (self.lastState != PaperFoldStateRightUnfolded) { + [self finishForState:PaperFoldStateRightUnfolded]; } self.lastState = self.state; self.state = PaperFoldStateRightUnfolded; @@ -299,11 +303,9 @@ - (void)unfoldLeftView:(NSTimer*)timer transform = CGAffineTransformMakeTranslation(self.leftFoldView.frame.size.width, 0); [self.contentView setTransform:transform]; - // if (self.lastState!=PaperFoldStateLeftUnfolded && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - // { - // [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateLeftUnfolded]; + // if (self.lastState != PaperFoldStateLeftUnfolded) { + // [self finishForState:PaperFoldStateLeftUnfolded]; // } - // [self setIsAutomatedFolding:NO]; } // use the x value to animate folding @@ -324,11 +326,9 @@ - (void)unfoldRightView:(NSTimer*)timer transform = CGAffineTransformMakeTranslation(-self.rightFoldView.frame.size.width, 0); [self.contentView setTransform:transform]; - // if (self.lastState!=PaperFoldStateRightUnfolded && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - // { - // [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateRightUnfolded]; + // if (self.lastState != PaperFoldStateRightUnfolded) { + // [self finishForState:PaperFoldStateRightUnfolded]; // } - // [self setIsAutomatedFolding:NO]; } // use the x value to animate folding @@ -352,16 +352,9 @@ - (void)restoreView:(NSTimer*)timer [self.contentView setTransform:transform]; [self animateWithContentOffset:CGPointMake(0, 0) panned:NO]; - if (self.lastState!=PaperFoldStateDefault) { - if (self.completionBlock != nil) { - self.completionBlock(); - self.completionBlock = nil; - } else if ([self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateDefault]; - } + if (self.lastState != PaperFoldStateDefault) { + [self finishForState:PaperFoldStateDefault]; } - [self setIsAutomatedFolding:NO]; } else { @@ -414,7 +407,9 @@ - (void)setPaperFoldState:(PaperFoldState)state animated:(BOOL)animated - (void)setPaperFoldState:(PaperFoldState)state { + self.showDividerLines = YES; [self setIsAutomatedFolding:YES]; + if (state==PaperFoldStateDefault) { self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(restoreView:) userInfo:nil repeats:YES]; @@ -453,4 +448,45 @@ - (void)restoreToCenter [self setPaperFoldState:PaperFoldStateDefault]; } +#pragma mark - Private methods + +- (void)finishForState:(PaperFoldState)state +{ + [self setShowDividerLines:NO animated:YES]; + + // we prefer executing the completion block, otherwise we notify the delegate + if (self.completionBlock != nil) { + self.completionBlock(); + self.completionBlock = nil; + + } else if ([self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) { + [self.delegate paperFoldView:self + didFoldAutomatically:self.isAutomatedFolding + toState:state]; + } + + // no more animations + [self setIsAutomatedFolding:NO]; +} + +- (void)setShowDividerLines:(BOOL)showDividerLines +{ + [self setShowDividerLines:showDividerLines animated:NO]; +} + +- (void)setShowDividerLines:(BOOL)showDividerLines animated:(BOOL)animated +{ + if (_showDividerLines == showDividerLines) + return; + + _showDividerLines = showDividerLines; + [UIView animateWithDuration:animated ? 0.25 : 0 + animations: + ^{ + self.leftDividerLine.alpha = showDividerLines ? 1 : 0; + self.rightDividerLine.alpha = showDividerLines ? 1 : 0; + }]; +} + + @end From 9d07138ed9483f35b3b03c53ba416bfb016efb72 Mon Sep 17 00:00:00 2001 From: honcheng Date: Tue, 20 Nov 2012 17:06:25 +0800 Subject: [PATCH 03/17] updated README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f4baaf5..8705b9c 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Apps that uses PaperFold , [LargeType](https://itunes.apple.com/sg/app/largetype-full-screen-text/id568459406) , [NextRide](https://itunes.apple.com/us/app/nextride-singapore-public/id565103559) , [SG NextBus](https://itunes.apple.com/sg/app/sg-nextbus/id361404839) +, [Hangzhou Metro](https://itunes.apple.com/cn/app/hang-zhou-de-tie/id518531257?mt=8) [Contact me](http://twitter.com/honcheng) if you want your app listed here. Thanks From 6fd828a1f3c831028270e1cb91b57378241567e5 Mon Sep 17 00:00:00 2001 From: honcheng Date: Fri, 23 Nov 2012 08:21:46 +0800 Subject: [PATCH 04/17] added option to drag left/right folds from the edge of the screen, but ignores any horizontal panning gestures in the middle. disabled by default --- PaperFold/PaperFold/DemoRootViewController.m | 1 + .../PaperFold/PaperFold/PaperFoldConstants.h | 1 + PaperFold/PaperFold/PaperFold/PaperFoldView.h | 3 ++- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 21 ++++++++++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/PaperFold/PaperFold/DemoRootViewController.m b/PaperFold/PaperFold/DemoRootViewController.m index b3a95c1..113026a 100644 --- a/PaperFold/PaperFold/DemoRootViewController.m +++ b/PaperFold/PaperFold/DemoRootViewController.m @@ -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; } diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldConstants.h b/PaperFold/PaperFold/PaperFold/PaperFoldConstants.h index 08a407f..d003f99 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldConstants.h +++ b/PaperFold/PaperFold/PaperFold/PaperFoldConstants.h @@ -14,6 +14,7 @@ #define kRightViewUnfoldThreshold 0.3 #define kTopViewUnfoldThreshold 0.3 #define kBottomViewUnfoldThreshold 0.3 +#define kEdgeScrollWidth 35.0 typedef enum { diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.h b/PaperFold/PaperFold/PaperFold/PaperFoldView.h index 608a2b3..ba7f5bb 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.h +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.h @@ -49,7 +49,7 @@ typedef void (^CompletionBlock)(); - (void)paperFoldView:(id)paperFoldView viewDidOffset:(CGPoint)offset; @end -@interface PaperFoldView : UIView +@interface PaperFoldView : UIView // main content view @property (nonatomic, strong) TouchThroughUIView *contentView; @@ -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 delegate; diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index a077b7b..c410e49 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -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; @@ -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]; @@ -188,7 +195,7 @@ - (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]; @@ -196,7 +203,16 @@ - (void)onContentViewPanned:(UIPanGestureRecognizer*)gesture { 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 @@ -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) { From 21f2fb197bd31565bd45244de0b995d9087c314d Mon Sep 17 00:00:00 2001 From: honcheng Date: Fri, 23 Nov 2012 08:26:32 +0800 Subject: [PATCH 05/17] check if contentView is MKMapView using NSClassFromString to prevent compiler error if user do not use MKMapVIew --- PaperFold/PaperFold/PaperFold/MultiFoldView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PaperFold/PaperFold/PaperFold/MultiFoldView.m b/PaperFold/PaperFold/PaperFold/MultiFoldView.m index 061c0cb..e53099d 100644 --- a/PaperFold/PaperFold/PaperFold/MultiFoldView.m +++ b/PaperFold/PaperFold/PaperFold/MultiFoldView.m @@ -85,7 +85,7 @@ - (id)initWithFrame:(CGRect)frame folds:(int)folds pullFactor:(float)factor - (void)setContent:(UIView *)contentView { - if ([contentView isKindOfClass:[MKMapView class]]) _shouldTakeScreenshotBeforeUnfolding = YES; + if ([contentView isKindOfClass:NSClassFromString(@"MKMapView")]) _shouldTakeScreenshotBeforeUnfolding = YES; // set the content view self.contentViewHolder = [[UIView alloc] initWithFrame:CGRectMake(0,0,contentView.frame.size.width,contentView.frame.size.height)]; From f7f304e0ba189c4c2d3355481a3adfdfea9cd918 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Sat, 24 Nov 2012 13:33:56 +1100 Subject: [PATCH 06/17] Post-merge fix. Re-added auto-hiding of divider lines and added the same for the top and bottom lines. --- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 56aab1c..13183d6 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -40,6 +40,8 @@ @interface PaperFoldView () @property (nonatomic, weak) UIView *leftDividerLine; @property (nonatomic, weak) UIView *rightDividerLine; +@property (nonatomic, weak) UIView *topDividerLine; +@property (nonatomic, weak) UIView *bottomDividerLine; @property (nonatomic, copy) CompletionBlock completionBlock; @property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer; @@ -118,7 +120,6 @@ - (void)setLeftFoldContentView:(UIView*)view foldCount:(int)leftViewFoldCount pu //[self.leftFoldView setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleHeight]; //[view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; - [self setPaperFoldState:PaperFoldStateDefault]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(-1,0,1,self.frame.size.height)]; [line setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; @@ -140,14 +141,13 @@ - (void)setBottomFoldContentView:(UIView*)view [self insertSubview:self.bottomFoldView belowSubview:self.contentView]; [self.bottomFoldView setContent:view]; [view setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; - [self setPaperFoldState:PaperFoldStateDefault]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0,self.frame.size.height,self.frame.size.width,1)]; [line setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; [self.contentView addSubview:line]; [line setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:0.5]]; line.alpha = 0; - self.rightDividerLine = line; + self.bottomDividerLine = line; self.enableBottomFoldDragging = YES; } @@ -161,13 +161,14 @@ - (void)setRightFoldContentView:(UIView*)view foldCount:(int)rightViewFoldCount [self.contentView insertSubview:self.rightFoldView atIndex:0]; [self.rightFoldView setContent:view]; [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; - [self setPaperFoldState:PaperFoldStateDefault]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width,0,1,self.frame.size.height)]; [line setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; [self.contentView addSubview:line]; [line setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight]; [line setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:0.5]]; + line.alpha = 0; + self.rightDividerLine = line; self.enableRightFoldDragging = YES; } @@ -187,13 +188,14 @@ - (void)setTopFoldContentView:(UIView*)view topViewFoldCount:(int)topViewFoldCou [self.contentView insertSubview:self.topFoldView atIndex:0]; [self.topFoldView setContent:view]; [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; - [self setPaperFoldState:PaperFoldStateDefault]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0,-1,self.contentView.frame.size.width,1)]; [line setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; [self.contentView addSubview:line]; [line setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight]; [line setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:0.5]]; + line.alpha = 0; + self.topDividerLine = line; self.enableTopFoldDragging = YES; } @@ -205,7 +207,11 @@ - (void)onContentViewPanned:(UIPanGestureRecognizer*)gesture if ([gesture state]==UIGestureRecognizerStateBegan) { - CGPoint velocity = [gesture velocityInView:self]; + // show the divider while dragging + [self setShowDividerLines:YES animated:YES]; + + + CGPoint velocity = [gesture velocityInView:self]; if ( abs(velocity.x) > abs(velocity.y)) { if (self.state==PaperFoldStateDefault) @@ -231,6 +237,11 @@ - (void)onContentViewPanned:(UIPanGestureRecognizer*)gesture { [self onContentViewPannedVertically:gesture]; } + + if (gesture.state != UIGestureRecognizerStateChanged) { + // hide the divider line + [self setShowDividerLines:NO animated:YES]; + } } } @@ -792,6 +803,28 @@ - (void)restoreToCenter [self setPaperFoldState:PaperFoldStateDefault]; } +- (void)setShowDividerLines:(BOOL)showDividerLines +{ + [self setShowDividerLines:showDividerLines animated:NO]; +} + +- (void)setShowDividerLines:(BOOL)showDividerLines animated:(BOOL)animated +{ + if (_showDividerLines == showDividerLines) + return; + + _showDividerLines = showDividerLines; + CGFloat alpha = showDividerLines ? 1 : 0; + [UIView animateWithDuration:animated ? 0.25 : 0 + animations: + ^{ + self.leftDividerLine.alpha = alpha; + self.topDividerLine.alpha = alpha; + self.rightDividerLine.alpha = alpha; + self.bottomDividerLine.alpha = alpha; + }]; +} + #pragma mark MultiFoldView delegate - (CGFloat)displacementOfMultiFoldView:(id)multiFoldView From fc22257b27f8148049d506918ad3d6910ece35b8 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Sat, 24 Nov 2012 14:10:24 +1100 Subject: [PATCH 07/17] Restored by previous work on completion blocks which apparently got lost --- PaperFold/PaperFold/PaperFold/PaperFoldView.h | 4 +- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 104 +++++++++--------- 2 files changed, 55 insertions(+), 53 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.h b/PaperFold/PaperFold/PaperFold/PaperFoldView.h index 608a2b3..6e03b00 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.h +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.h @@ -49,7 +49,7 @@ typedef void (^CompletionBlock)(); - (void)paperFoldView:(id)paperFoldView viewDidOffset:(CGPoint)offset; @end -@interface PaperFoldView : UIView +@interface PaperFoldView : UIView // main content view @property (nonatomic, strong) TouchThroughUIView *contentView; @@ -77,6 +77,8 @@ typedef void (^CompletionBlock)(); // non-optimized is always the non-retina image @property (nonatomic, assign) BOOL useOptimizedScreenshot; +@property (nonatomic, assign) CGRect restrictedDraggingRect; + // animate folding and unfolding when sent the offset of contentView // offset are either sent from pan gesture recognizer, or manual animation done with NSTimer after gesture ended - (void)animateWithContentOffset:(CGPoint)point panned:(BOOL)panned; diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 13183d6..12e0c98 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -393,11 +393,9 @@ - (void)animateWithContentOffset:(CGPoint)point panned:(BOOL)panned // set the limit of the right offset if (x>=self.leftFoldView.frame.size.width) { - if (self.lastState!=PaperFoldStateLeftUnfolded && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateLeftUnfolded]; - [self setIsAutomatedFolding:NO]; - } + if (self.lastState != PaperFoldStateLeftUnfolded) { + [self finishForState:PaperFoldStateLeftUnfolded]; + } self.lastState = self.state; self.state = PaperFoldStateLeftUnfolded; x = self.leftFoldView.frame.size.width; @@ -421,11 +419,9 @@ - (void)animateWithContentOffset:(CGPoint)point panned:(BOOL)panned float x1 = x; if (x1<=-self.rightFoldView.frame.size.width) { - if (self.lastState!=PaperFoldStateRightUnfolded && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateRightUnfolded]; - [self setIsAutomatedFolding:NO]; - } + if (self.lastState != PaperFoldStateRightUnfolded) { + [self finishForState:PaperFoldStateRightUnfolded]; + } self.lastState = self.state; self.state = PaperFoldStateRightUnfolded; x1 = -self.rightFoldView.frame.size.width; @@ -536,12 +532,10 @@ - (void)unfoldBottomView:(NSTimer*)timer [timer invalidate]; transform = CGAffineTransformMakeTranslation(0,-1*self.bottomFoldView.frame.size.height); [self.contentView setTransform:transform]; - - if (self.lastState!=PaperFoldStateBottomUnfolded && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateBottomUnfolded]; - } - [self setIsAutomatedFolding:NO]; + + if (self.lastState != PaperFoldStateBottomUnfolded) { + [self finishForState:PaperFoldStateBottomUnfolded]; + } } // use the x value to animate folding @@ -596,11 +590,9 @@ - (void)unfoldTopView:(NSTimer*)timer transform = CGAffineTransformMakeTranslation(0,self.topFoldView.frame.size.height); [self.contentView setTransform:transform]; - if (self.lastState!=PaperFoldStateTopUnfolded && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateTopUnfolded]; - } - [self setIsAutomatedFolding:NO]; + if (self.lastState != PaperFoldStateTopUnfolded) { + [self finishForState:PaperFoldStateTopUnfolded]; + } } // use the x value to animate folding @@ -650,15 +642,10 @@ - (void)restoreView:(NSTimer*)timer [self.contentView setTransform:transform]; [self animateWithContentOffset:CGPointMake(0, 0) panned:NO]; - if (self.lastState!=PaperFoldStateDefault) - { - if ([self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateDefault]; - } - self.state = PaperFoldStateDefault; - } - [self setIsAutomatedFolding:NO]; + if (self.lastState != PaperFoldStateDefault) { + [self finishForState:PaperFoldStateDefault]; + } + self.state = PaperFoldStateDefault; } else { @@ -682,15 +669,10 @@ - (void)restoreView:(NSTimer*)timer [self.contentView setTransform:transform]; [self animateWithContentOffset:CGPointMake(0, 0) panned:NO]; - if (self.lastState!=PaperFoldStateDefault) - { - if ([self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:self.isAutomatedFolding toState:PaperFoldStateDefault]; - } - self.state = PaperFoldStateDefault; - } - [self setIsAutomatedFolding:NO]; + if (self.lastState != PaperFoldStateDefault) { + [self finishForState:PaperFoldStateDefault]; + } + self.state = PaperFoldStateDefault; } else @@ -719,10 +701,9 @@ - (void)setPaperFoldState:(PaperFoldState)state animated:(BOOL)animated CGAffineTransform transform = transform = CGAffineTransformMakeTranslation(0, 0); [self.contentView setTransform:transform]; - if (self.lastState!=PaperFoldStateDefault && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:YES toState:PaperFoldStateDefault]; - } + if (self.lastState != PaperFoldStateDefault) { + [self finishForState:PaperFoldStateDefault]; + } } else if (state==PaperFoldStateLeftUnfolded) { @@ -732,10 +713,9 @@ - (void)setPaperFoldState:(PaperFoldState)state animated:(BOOL)animated [self.contentView setTransform:transform]; [self.leftFoldView unfoldWithoutAnimation]; - if (self.lastState!=PaperFoldStateLeftUnfolded && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:YES toState:PaperFoldStateLeftUnfolded]; - } + if (self.lastState != PaperFoldStateLeftUnfolded) { + [self finishForState:PaperFoldStateLeftUnfolded]; + } } else if (state==PaperFoldStateRightUnfolded) { @@ -745,10 +725,9 @@ - (void)setPaperFoldState:(PaperFoldState)state animated:(BOOL)animated [self.contentView setTransform:transform]; [self.rightFoldView unfoldWithoutAnimation]; - if (self.lastState!=PaperFoldStateRightUnfolded && [self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) - { - [self.delegate paperFoldView:self didFoldAutomatically:YES toState:PaperFoldStateRightUnfolded]; - } + if (self.lastState != PaperFoldStateRightUnfolded) { + [self finishForState:PaperFoldStateRightUnfolded]; + } } self.state = state; } @@ -803,6 +782,27 @@ - (void)restoreToCenter [self setPaperFoldState:PaperFoldStateDefault]; } +- (void)finishForState:(PaperFoldState)state +{ + [self setShowDividerLines:NO animated:YES]; + + // we prefer executing the completion block, otherwise we notify the delegate + if (self.completionBlock != nil) { + self.completionBlock(); + self.completionBlock = nil; + + } else if ([self.delegate respondsToSelector:@selector(paperFoldView:didFoldAutomatically:toState:)]) { + [self.delegate paperFoldView:self + didFoldAutomatically:self.isAutomatedFolding + toState:state]; + } + + // no more animations + [self setIsAutomatedFolding:NO]; +} + + + - (void)setShowDividerLines:(BOOL)showDividerLines { [self setShowDividerLines:showDividerLines animated:NO]; @@ -825,7 +825,7 @@ - (void)setShowDividerLines:(BOOL)showDividerLines animated:(BOOL)animated }]; } -#pragma mark MultiFoldView delegate +#pragma mark - MultiFoldView delegate - (CGFloat)displacementOfMultiFoldView:(id)multiFoldView { From 3352eba30c425bedba819af6219bcff66954cac0 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Sat, 24 Nov 2012 14:12:07 +1100 Subject: [PATCH 08/17] Optional property 'restrictedDraggingRect' to, say, restrict dragging to a navigation bar --- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 12e0c98..a41fc6d 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -85,6 +85,7 @@ - (void)initialize [_contentView setAutoresizesSubviews:YES]; UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onContentViewPanned:)]; + panGestureRecognizer.delegate = self; [_contentView addGestureRecognizer:panGestureRecognizer]; _state = PaperFoldStateDefault; @@ -93,6 +94,7 @@ - (void)initialize _enableLeftFoldDragging = NO; _enableBottomFoldDragging = NO; _enableTopFoldDragging = NO; + _restrictedDraggingRect = CGRectNull; _showDividerLines = NO; } @@ -204,13 +206,12 @@ - (void)onContentViewPanned:(UIPanGestureRecognizer*)gesture { // cancel gesture if another animation has not finished yet if ([self.animationTimer isValid]) return; - + if ([gesture state]==UIGestureRecognizerStateBegan) { // show the divider while dragging [self setShowDividerLines:YES animated:YES]; - CGPoint velocity = [gesture velocityInView:self]; if ( abs(velocity.x) > abs(velocity.y)) { @@ -862,4 +863,17 @@ - (CGFloat)displacementOfMultiFoldView:(id)multiFoldView return 0.0; } +#pragma mark - Gesture recogniser delegate + +- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer +{ + // only allow panning if we didn't restrict it to start at a certain rect + if (NO == CGRectIsNull(self.restrictedDraggingRect) + && NO == CGRectContainsPoint(self.restrictedDraggingRect, [gestureRecognizer locationInView:self])) { + return NO; + } else { + return YES; + } +} + @end From 1e641d15c5e10cba8cc21f18b0be4acf15a59f95 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Sat, 24 Nov 2012 14:13:13 +1100 Subject: [PATCH 09/17] Description of 'restrictedDraggingRect' --- PaperFold/PaperFold/PaperFold/PaperFoldView.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.h b/PaperFold/PaperFold/PaperFold/PaperFoldView.h index 6e03b00..30a5c5f 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.h +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.h @@ -76,7 +76,8 @@ typedef void (^CompletionBlock)(); // optimized screenshot follows the scale of the screen // non-optimized is always the non-retina image @property (nonatomic, assign) BOOL useOptimizedScreenshot; - +// restrict the dragging gesture recogniser to a certain UIRect of this view. Useful to restrict +// dragging to, say, a navigation bar. @property (nonatomic, assign) CGRect restrictedDraggingRect; // animate folding and unfolding when sent the offset of contentView From a163be65dd7987d7378522edf34e0daabee5b165 Mon Sep 17 00:00:00 2001 From: honcheng Date: Sun, 2 Dec 2012 10:22:47 +0800 Subject: [PATCH 10/17] fixed: side shadow in the wrong direction --- PaperFold/PaperFold/PaperFold/ShadowView.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/ShadowView.m b/PaperFold/PaperFold/PaperFold/ShadowView.m index c6413dd..a7a66a4 100755 --- a/PaperFold/PaperFold/PaperFold/ShadowView.m +++ b/PaperFold/PaperFold/PaperFold/ShadowView.m @@ -44,15 +44,15 @@ - (id)initWithFrame:(CGRect)frame foldDirection:(FoldDirection)foldDirection _gradient = [CAGradientLayer layer]; [_gradient setFrame:CGRectMake(0,0,frame.size.width,frame.size.height)]; - if (foldDirection==FoldDirectionHorizontalRightToLeft) - { - [_gradient setStartPoint:CGPointMake(0, 0)]; - [_gradient setEndPoint:CGPointMake(1, 0)]; - } - else if (foldDirection==FoldDirectionVertical) + if (foldDirection==FoldDirectionVertical) { [_gradient setStartPoint:CGPointMake(0, 1)]; [_gradient setEndPoint:CGPointMake(0, 0)]; + } + else + { + [_gradient setStartPoint:CGPointMake(0, 0)]; + [_gradient setEndPoint:CGPointMake(1, 0)]; } [self.layer insertSublayer:_gradient atIndex:0]; [self setBackgroundColor:[UIColor clearColor]]; From a3b4129ad323b0063e8a462e9d4be592a0dd41fc Mon Sep 17 00:00:00 2001 From: honcheng Date: Mon, 3 Dec 2012 08:04:18 +0800 Subject: [PATCH 11/17] fixed: crashes when UIGraphicsGetCurrentContext is nil. This happens when it tries to take a screenshot of a UIView with CGRectZero. This no longer crashes, but when rect is zero, there is no view to reveal --- PaperFold/PaperFold/PaperFold/MultiFoldView.m | 31 ++++++++++++------- .../PaperFold/PaperFold/UIView+Screenshot.m | 29 +++++++++++------ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/MultiFoldView.m b/PaperFold/PaperFold/PaperFold/MultiFoldView.m index 061c0cb..fa71a02 100644 --- a/PaperFold/PaperFold/PaperFold/MultiFoldView.m +++ b/PaperFold/PaperFold/PaperFold/MultiFoldView.m @@ -128,15 +128,19 @@ - (void)setScreenshotImage:(UIImage*)image for (int i=0; i Date: Mon, 3 Dec 2012 08:19:33 +0800 Subject: [PATCH 12/17] - exposes divider lines for those that want to hide it. --- PaperFold/PaperFold/PaperFold/PaperFoldView.h | 7 +++++++ PaperFold/PaperFold/PaperFold/PaperFoldView.m | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.h b/PaperFold/PaperFold/PaperFold/PaperFoldView.h index 30a5c5f..8ced1b9 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.h +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.h @@ -79,6 +79,13 @@ typedef void (^CompletionBlock)(); // restrict the dragging gesture recogniser to a certain UIRect of this view. Useful to restrict // dragging to, say, a navigation bar. @property (nonatomic, assign) CGRect restrictedDraggingRect; +// divider lines +// these are exposed so that it is possible to hide the lines +// especially when views have rounded corners +@property (nonatomic, weak) UIView *leftDividerLine; +@property (nonatomic, weak) UIView *rightDividerLine; +@property (nonatomic, weak) UIView *topDividerLine; +@property (nonatomic, weak) UIView *bottomDividerLine; // animate folding and unfolding when sent the offset of contentView // offset are either sent from pan gesture recognizer, or manual animation done with NSTimer after gesture ended diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index a41fc6d..002af62 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -38,11 +38,6 @@ @interface PaperFoldView () -@property (nonatomic, weak) UIView *leftDividerLine; -@property (nonatomic, weak) UIView *rightDividerLine; -@property (nonatomic, weak) UIView *topDividerLine; -@property (nonatomic, weak) UIView *bottomDividerLine; - @property (nonatomic, copy) CompletionBlock completionBlock; @property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer; From 16af9b733284848e0fa224d77c6ba5031432568b Mon Sep 17 00:00:00 2001 From: honcheng Date: Mon, 3 Dec 2012 08:44:20 +0800 Subject: [PATCH 13/17] fixed: bottom view unfolds too fast --- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 002af62..1eed831 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -519,10 +519,10 @@ - (void)unfoldBottomView:(NSTimer*)timer [self.rightFoldView setHidden:YES]; CGAffineTransform transform = [self.contentView transform]; - float y = transform.ty - (self.bottomFoldView.frame.size.height-transform.ty)/4; + float y = transform.ty - (self.bottomFoldView.frame.size.height+transform.ty)/4; transform = CGAffineTransformMakeTranslation(0, y); [self.contentView setTransform:transform]; - + if (-y>=self.bottomFoldView.frame.size.height-2) { [timer invalidate]; @@ -579,7 +579,7 @@ - (void)unfoldTopView:(NSTimer*)timer float y = transform.ty + (self.topFoldView.frame.size.height-transform.ty)/8; transform = CGAffineTransformMakeTranslation(0, y); [self.contentView setTransform:transform]; - + if (y>=self.topFoldView.frame.size.height-5) { [timer invalidate]; From d8ff1edf8c2ff23a9db88db6eacc6887a578ca40 Mon Sep 17 00:00:00 2001 From: honcheng Date: Thu, 6 Dec 2012 14:26:50 +0800 Subject: [PATCH 14/17] hide the fold views initially until they are about to be unfolded --- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 1eed831..c46be17 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -114,6 +114,7 @@ - (void)setLeftFoldContentView:(UIView*)view foldCount:(int)leftViewFoldCount pu [self.leftFoldView setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; [self insertSubview:self.leftFoldView belowSubview:self.contentView]; [self.leftFoldView setContent:view]; + [self.leftFoldView setHidden:YES]; //[self.leftFoldView setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleHeight]; //[view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; @@ -137,6 +138,7 @@ - (void)setBottomFoldContentView:(UIView*)view [self.bottomFoldView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; [self insertSubview:self.bottomFoldView belowSubview:self.contentView]; [self.bottomFoldView setContent:view]; + [self.bottomFoldView setHidden:YES]; [view setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0,self.frame.size.height,self.frame.size.width,1)]; @@ -157,6 +159,7 @@ - (void)setRightFoldContentView:(UIView*)view foldCount:(int)rightViewFoldCount [self.rightFoldView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight]; [self.contentView insertSubview:self.rightFoldView atIndex:0]; [self.rightFoldView setContent:view]; + [self.rightFoldView setHidden:YES]; [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width,0,1,self.frame.size.height)]; @@ -184,6 +187,7 @@ - (void)setTopFoldContentView:(UIView*)view topViewFoldCount:(int)topViewFoldCou [self.topFoldView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight]; [self.contentView insertSubview:self.topFoldView atIndex:0]; [self.topFoldView setContent:view]; + [self.topFoldView setHidden:YES]; [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0,-1,self.contentView.frame.size.width,1)]; From 8175a7891d07bf2aa5517e53635c26432f7cc91e Mon Sep 17 00:00:00 2001 From: honcheng Date: Fri, 7 Dec 2012 09:14:49 +0800 Subject: [PATCH 15/17] resize left/right fold view when paper fold view is resized --- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index c410e49..a2fa738 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -91,6 +91,19 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni else return NO; } +- (void)setFrame:(CGRect)frame +{ + [super setFrame:frame]; + + CGRect leftFoldViewFrame = self.leftFoldView.frame; + leftFoldViewFrame.size.height = frame.size.height; + [self.leftFoldView setFrame:leftFoldViewFrame]; + + CGRect rightFoldViewFrame = self.rightFoldView.frame; + rightFoldViewFrame.size.height = frame.size.height; + [self.rightFoldView setFrame:leftFoldViewFrame]; +} + - (void)setCenterContentView:(UIView*)view { [view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; From c838c595ac3344e7d624431eec29d3db92105c1d Mon Sep 17 00:00:00 2001 From: honcheng Date: Fri, 7 Dec 2012 09:37:39 +0800 Subject: [PATCH 16/17] when enableHorizontalEdgeDragging is turned on, check that other gestures at the edges are disabled increased dragging edge width --- .../PaperFold/PaperFold/PaperFoldConstants.h | 2 +- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 21 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldConstants.h b/PaperFold/PaperFold/PaperFold/PaperFoldConstants.h index d003f99..7ef0f85 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldConstants.h +++ b/PaperFold/PaperFold/PaperFold/PaperFoldConstants.h @@ -14,7 +14,7 @@ #define kRightViewUnfoldThreshold 0.3 #define kTopViewUnfoldThreshold 0.3 #define kBottomViewUnfoldThreshold 0.3 -#define kEdgeScrollWidth 35.0 +#define kEdgeScrollWidth 40.0 typedef enum { diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 765c730..685cf20 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -94,12 +94,6 @@ - (void)initialize _showDividerLines = NO; } -- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer -{ - if (self.enableHorizontalEdgeDragging) return YES; - else return NO; -} - - (void)setFrame:(CGRect)frame { [super setFrame:frame]; @@ -892,6 +886,21 @@ - (CGFloat)displacementOfMultiFoldView:(id)multiFoldView #pragma mark - Gesture recogniser delegate +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer +{ + if (self.enableHorizontalEdgeDragging) + { + CGPoint location = [gestureRecognizer locationInView:self.contentView]; + if (location.x < kEdgeScrollWidth || location.x > (self.contentView.frame.size.width-kEdgeScrollWidth)) + { + + return NO; + } + else return YES; + } + else return NO; +} + - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { // only allow panning if we didn't restrict it to start at a certain rect From 1abef49e0aea244e725bcbf88dee76ac764e4936 Mon Sep 17 00:00:00 2001 From: honcheng Date: Fri, 7 Dec 2012 09:54:14 +0800 Subject: [PATCH 17/17] fixed: rightFoldView not resized properly --- PaperFold/PaperFold/PaperFold/PaperFoldView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PaperFold/PaperFold/PaperFold/PaperFoldView.m b/PaperFold/PaperFold/PaperFold/PaperFoldView.m index 685cf20..75699b7 100644 --- a/PaperFold/PaperFold/PaperFold/PaperFoldView.m +++ b/PaperFold/PaperFold/PaperFold/PaperFoldView.m @@ -104,7 +104,7 @@ - (void)setFrame:(CGRect)frame CGRect rightFoldViewFrame = self.rightFoldView.frame; rightFoldViewFrame.size.height = frame.size.height; - [self.rightFoldView setFrame:leftFoldViewFrame]; + [self.rightFoldView setFrame:rightFoldViewFrame]; } - (void)setCenterContentView:(UIView*)view @@ -341,7 +341,7 @@ - (void)onContentViewPannedHorizontally:(UIPanGestureRecognizer*)gesture [self.leftFoldView setHidden:NO]; [self.bottomFoldView setHidden:YES]; [self.topFoldView setHidden:YES]; - + CGPoint point = [gesture translationInView:self]; if ([gesture state]==UIGestureRecognizerStateChanged) {