Permalink
Browse files

Add enableBenableDraggingPastInsets property

By setting this property to NO along with enableBounces to NO a view similar to facebooks can be achieved.  For my purposes my stacked view only requires a single view controller so I am not sure how performance will change with multiple stacks
  • Loading branch information...
1 parent 150b81d commit dd411a291212d23f0c05f08ae6990979ba23b58d Alex Billingsley committed with Jan 24, 2012
Showing with 18 additions and 0 deletions.
  1. +3 −0 PSStackedView/PSStackedViewController.h
  2. +15 −0 PSStackedView/PSStackedViewController.m
@@ -118,6 +118,9 @@ enum {
/// Property to disable shadows
@property(nonatomic, assign) BOOL enableShadows;
+/// Property to disable dragging past left insets, recommend setting enableBouces to NO when this is set to NO
+@property(nonatomic, assign) BOOL enableDraggingPastInsets;
+
/// left inset thats always visible. Defaults to 60.
@property(nonatomic, assign) NSUInteger leftInset;
/// animate setting of the left inset that is always visible
@@ -63,6 +63,7 @@ @implementation PSStackedViewController
@synthesize reduceAnimations = reduceAnimations_;
@synthesize enableBounces = enableBounces_;
@synthesize enableShadows = enableShadows_;
+@synthesize enableDraggingPastInsets = enableDraggingPastInsets_;
@dynamic firstVisibleIndex;
#ifdef ALLOW_SWIZZLING_NAVIGATIONCONTROLLER
@@ -94,6 +95,7 @@ - (id)initWithRootViewController:(UIViewController *)rootViewController; {
self.panRecognizer = panRecognizer;
enableBounces_ = YES;
enableShadows_ = YES;
+ enableDraggingPastInsets_ = NO;
#ifdef ALLOW_SWIZZLING_NAVIGATIONCONTROLLER
@@ -722,6 +724,19 @@ - (void)moveStackWithOffset:(NSInteger)offset animated:(BOOL)animated userDraggi
leftViewController.containerView.left = leftVCLeftPosition;
}
+ if (enableDraggingPastInsets_ == NO)
+ {
+ int stackWidth = (!isTopViewController) ? 0 : (leftViewController) ? leftViewController.view.frame.size.width : (rightViewController) ? rightViewController.view.frame.size.width : 0;
+ int padding = 45;
+ if ((int)(currentVCLeftPosition-stackWidth) <= (int)leftInset_ ) {
+ currentVCLeftPosition = leftInset_ + stackWidth;
+ }
+ else if ((int)(currentVCLeftPosition-stackWidth) >= (int)largeLeftInset_ + padding) {
+ //For a more natural
+ currentVCLeftPosition = largeLeftInset_ + stackWidth + padding;
+ }
+ }
+
currentViewController.containerView.left = currentVCLeftPosition;
isTopViewController = NO; // there can only be one.

0 comments on commit dd411a2

Please sign in to comment.