Skip to content
This repository
Browse code

Merge pull request #21 from krzak/master

expose more parameters and allow a custom number of gestures for the sliding.
  • Loading branch information...
commit 1dcbed1b57e8f06f745f6d14a15cefa1cc840c6f 2 parents 822c69c + fb0fecd
Peter Steinberger authored February 26, 2012
9  PSStackedView/PSSVContainerView.h
@@ -49,4 +49,13 @@ enum {
49 49
 /// darken down the view if it's not fully visible
50 50
 @property(nonatomic, assign) CGFloat darkRatio;
51 51
 
  52
+/// shadow width
  53
+@property(nonatomic, assign) CGFloat shadowWidth;
  54
+
  55
+/// shadow alpha
  56
+@property(nonatomic, assign) CGFloat shadowAlpha;
  57
+
  58
+/// corner radius
  59
+@property(nonatomic, assign) CGFloat cornerRadius;
  60
+
52 61
 @end
20  PSStackedView/PSSVContainerView.m
@@ -10,10 +10,6 @@
10 10
 #import "PSStackedViewGlobal.h"
11 11
 #import "UIView+PSSizes.h"
12 12
 
13  
-#define kPSSVCornerRadius 6.f
14  
-#define kPSSVShadowWidth 60.f
15  
-#define kPSSVShadowAlpha 0.2f
16  
-
17 13
 @interface PSSVContainerView ()
18 14
 @property(nonatomic, assign) CGFloat originalWidth;
19 15
 @property(nonatomic, strong) CAGradientLayer *leftShadowLayer;
@@ -31,7 +27,9 @@ @implementation PSSVContainerView
31 27
 @synthesize innerShadowLayer = innerShadowLayer_;
32 28
 @synthesize rightShadowLayer = rightShadowLayer_;
33 29
 @synthesize transparentView = transparentView_;
34  
-
  30
+@synthesize shadowWidth = shadowWidth_;
  31
+@synthesize shadowAlpha = shadowAlpha_;
  32
+@synthesize cornerRadius = cornerRadius_;
35 33
 ///////////////////////////////////////////////////////////////////////////////////////////////////
36 34
 #pragma mark -
37 35
 #pragma mark private
@@ -41,7 +39,7 @@ - (CAGradientLayer *)shadowAsInverse:(BOOL)inverse {
41 39
 	CAGradientLayer *newShadow = [[CAGradientLayer alloc] init];
42 40
     newShadow.startPoint = CGPointMake(0, 0.5);
43 41
     newShadow.endPoint = CGPointMake(1.0, 0.5);
44  
-	CGColorRef darkColor  = (CGColorRef)CFRetain([UIColor colorWithWhite:0.0f alpha:kPSSVShadowAlpha].CGColor);
  42
+	CGColorRef darkColor  = (CGColorRef)CFRetain([UIColor colorWithWhite:0.0f alpha:shadowAlpha_].CGColor);
45 43
 	CGColorRef lightColor = (CGColorRef)CFRetain([UIColor clearColor].CGColor);
46 44
 	newShadow.colors = [NSArray arrayWithObjects:
47 45
                         (__bridge id)(inverse ? lightColor : darkColor),
@@ -147,7 +145,7 @@ - (void)addMaskToCorners:(UIRectCorner)corners; {
147 145
     // Create the path (with only the top-left corner rounded)
148 146
     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:frame 
149 147
                                                    byRoundingCorners:corners
150  
-                                                         cornerRadii:CGSizeMake(kPSSVCornerRadius, kPSSVCornerRadius)];
  148
+                                                         cornerRadii:CGSizeMake(cornerRadius_, cornerRadius_)];
151 149
     
152 150
     // Create the shape layer and set its path
153 151
     CAShapeLayer *maskLayer = [CAShapeLayer layer];
@@ -175,7 +173,7 @@ - (void)setShadow:(PSSVSide)shadow {
175 173
             CAGradientLayer *leftShadow = [self shadowAsInverse:YES];
176 174
             self.leftShadowLayer = leftShadow;
177 175
         }
178  
-        self.leftShadowLayer.frame = CGRectMake(-kPSSVShadowWidth, 0, kPSSVShadowWidth+kPSSVCornerRadius, self.controller.view.height);;
  176
+        self.leftShadowLayer.frame = CGRectMake(-shadowWidth_, 0, shadowWidth_+cornerRadius_, self.controller.view.height);;
179 177
         if ([self.layer.sublayers indexOfObjectIdenticalTo:self.leftShadowLayer] != 0) {
180 178
             [self.layer insertSublayer:self.leftShadowLayer atIndex:0];
181 179
         }
@@ -188,7 +186,7 @@ - (void)setShadow:(PSSVSide)shadow {
188 186
             CAGradientLayer *rightShadow = [self shadowAsInverse:NO];
189 187
             self.rightShadowLayer = rightShadow;
190 188
         }
191  
-        self.rightShadowLayer.frame = CGRectMake(self.width-kPSSVCornerRadius, 0, kPSSVShadowWidth, self.controller.view.height);
  189
+        self.rightShadowLayer.frame = CGRectMake(self.width-cornerRadius_, 0, shadowWidth_, self.controller.view.height);
192 190
         if ([self.layer.sublayers indexOfObjectIdenticalTo:self.rightShadowLayer] != 0) {
193 191
             [self.layer insertSublayer:self.rightShadowLayer atIndex:0];
194 192
         }
@@ -199,10 +197,10 @@ - (void)setShadow:(PSSVSide)shadow {
199 197
     if (shadow) {
200 198
         if (!self.innerShadowLayer) {
201 199
             CAGradientLayer *innerShadow = [[CAGradientLayer alloc] init];
202  
-            innerShadow.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithWhite:0.0f alpha:kPSSVShadowAlpha].CGColor, (id)[UIColor colorWithWhite:0.0f alpha:kPSSVShadowAlpha].CGColor, nil];
  200
+            innerShadow.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithWhite:0.0f alpha:shadowAlpha_].CGColor, (id)[UIColor colorWithWhite:0.0f alpha:shadowAlpha_].CGColor, nil];
203 201
             self.innerShadowLayer = innerShadow;
204 202
         }
205  
-        self.innerShadowLayer.frame = CGRectMake(kPSSVCornerRadius, 0, self.width-kPSSVCornerRadius*2, self.controller.view.height);
  203
+        self.innerShadowLayer.frame = CGRectMake(cornerRadius_, 0, self.width-cornerRadius_*2, self.controller.view.height);
206 204
         if ([self.layer.sublayers indexOfObjectIdenticalTo:self.innerShadowLayer] != 0) {
207 205
             [self.layer insertSublayer:self.innerShadowLayer atIndex:0];
208 206
         }
17  PSStackedView/PSStackedViewController.h
@@ -121,6 +121,21 @@ enum {
121 121
 /// Property to disable dragging past left insets, recommend setting enableBouces to NO when this is set to NO
122 122
 @property(nonatomic, assign) BOOL enableDraggingPastInsets;
123 123
 
  124
+/// enable scaling while fade in/out
  125
+@property(nonatomic, assign) BOOL enableScalingFadeInOut;
  126
+
  127
+/// shadow width
  128
+@property(nonatomic, assign) CGFloat defaultShadowWidth;
  129
+
  130
+/// shadow alpha
  131
+@property(nonatomic, assign) CGFloat defaultShadowAlpha;
  132
+
  133
+/// corner radius
  134
+@property(nonatomic, assign) CGFloat cornerRadius;
  135
+
  136
+///number of touches
  137
+@property(nonatomic, assign) NSUInteger numberOfTouches;
  138
+
124 139
 /// left inset thats always visible. Defaults to 60.
125 140
 @property(nonatomic, assign) NSUInteger leftInset;
126 141
 /// animate setting of the left inset that is always visible
@@ -131,6 +146,8 @@ enum {
131 146
 /// animate setting of large left inset
132 147
 - (void)setLargeLeftInset:(NSUInteger)largeLeftInset animated:(BOOL)animated;
133 148
 
  149
+
  150
+
134 151
 // compatibility with UINavigationBar -- returns nil
135 152
 #ifdef ALLOW_SWIZZLING_NAVIGATIONCONTROLLER
136 153
 @property(nonatomic, assign) UINavigationBar *navigationBar;
60  PSStackedView/PSStackedViewController.m
@@ -64,6 +64,11 @@ @implementation PSStackedViewController
64 64
 @synthesize enableBounces = enableBounces_;
65 65
 @synthesize enableShadows = enableShadows_;
66 66
 @synthesize enableDraggingPastInsets = enableDraggingPastInsets_;
  67
+@synthesize enableScalingFadeInOut = enableScalingFadeInOut_;
  68
+@synthesize defaultShadowWidth = defaultShadowWidth_;
  69
+@synthesize defaultShadowAlpha  = defaultShadowAlpha_;
  70
+@synthesize cornerRadius = cornerRadius_;
  71
+@synthesize numberOfTouches = numberOfTouches_;
67 72
 @dynamic firstVisibleIndex;
68 73
 
69 74
 #ifdef ALLOW_SWIZZLING_NAVIGATIONCONTROLLER
@@ -73,6 +78,26 @@ @implementation PSStackedViewController
73 78
 ///////////////////////////////////////////////////////////////////////////////////////////////////
74 79
 #pragma mark - NSObject
75 80
 
  81
+- (void)configureGestureRecognizer
  82
+{
  83
+    [self.view removeGestureRecognizer:self.panRecognizer];
  84
+    
  85
+    // add a gesture recognizer to detect dragging to the guest controllers
  86
+    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)];
  87
+    if (numberOfTouches_ > 0)
  88
+    {
  89
+        [panRecognizer setMinimumNumberOfTouches:numberOfTouches_];
  90
+    } else {
  91
+        [panRecognizer setMaximumNumberOfTouches:1];            
  92
+    }
  93
+    [panRecognizer setDelaysTouchesBegan:NO];
  94
+    [panRecognizer setDelaysTouchesEnded:YES];
  95
+    [panRecognizer setCancelsTouchesInView:YES];
  96
+    panRecognizer.delegate = self;
  97
+    [self.view addGestureRecognizer:panRecognizer];
  98
+    self.panRecognizer = panRecognizer;
  99
+}
  100
+
76 101
 - (id)initWithRootViewController:(UIViewController *)rootViewController; {
77 102
     if ((self = [super init])) {
78 103
         rootViewController_ = rootViewController;
@@ -84,20 +109,16 @@ - (id)initWithRootViewController:(UIViewController *)rootViewController; {
84 109
         leftInset_ = 60;
85 110
         largeLeftInset_ = 200;
86 111
         
87  
-        // add a gesture recognizer to detect dragging to the guest controllers
88  
-        UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)];
89  
-        [panRecognizer setMaximumNumberOfTouches:1];
90  
-        [panRecognizer setDelaysTouchesBegan:NO];
91  
-        [panRecognizer setDelaysTouchesEnded:YES];
92  
-        [panRecognizer setCancelsTouchesInView:YES];
93  
-        panRecognizer.delegate = self;
94  
-        [self.view addGestureRecognizer:panRecognizer];
95  
-        self.panRecognizer = panRecognizer;
  112
+        [self configureGestureRecognizer];
  113
+
96 114
         enableBounces_ = YES;
97 115
         enableShadows_ = YES;
98 116
         enableDraggingPastInsets_ = YES;
99  
-        
100  
-        
  117
+        enableScalingFadeInOut_ = YES;
  118
+        defaultShadowWidth_ = 60.0f;
  119
+        defaultShadowAlpha_ = 0.2f;
  120
+        cornerRadius_ = 6.0f;
  121
+
101 122
 #ifdef ALLOW_SWIZZLING_NAVIGATIONCONTROLLER
102 123
         PSSVLog("Swizzling UIViewController.navigationController");
103 124
         Method origMethod = class_getInstanceMethod([UIViewController class], @selector(navigationController));
@@ -790,7 +811,7 @@ - (void)moveStackWithOffset:(NSInteger)offset animated:(BOOL)animated userDraggi
790 811
     } completion:nil];
791 812
 }
792 813
 
793  
-- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {
  814
+- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {    
794 815
     CGPoint translatedPoint = [recognizer translationInView:self.view];
795 816
     UIGestureRecognizerState state = recognizer.state;
796 817
     
@@ -939,6 +960,9 @@ - (void)pushViewController:(UIViewController *)viewController fromViewController
939 960
     container.left = leftGap;
940 961
     container.width = viewController.view.width;
941 962
     container.autoresizingMask = UIViewAutoresizingFlexibleHeight; // width is not flexible!
  963
+    container.shadowWidth = defaultShadowWidth_;
  964
+    container.shadowAlpha = defaultShadowAlpha_;
  965
+    container.cornerRadius = cornerRadius_;
942 966
     [container limitToMaxWidth:[self maxControllerWidth]];
943 967
     PSSVLog(@"container frame: %@", NSStringFromCGRect(container.frame));
944 968
     
@@ -947,7 +971,8 @@ - (void)pushViewController:(UIViewController *)viewController fromViewController
947 971
     
948 972
     if (animated) {
949 973
         container.alpha = 0.f;
950  
-        container.transform = CGAffineTransformMakeScale(1.2, 1.2); // large but fade in
  974
+        if (enableScalingFadeInOut_)
  975
+            container.transform = CGAffineTransformMakeScale(1.2, 1.2); // large but fade in
951 976
     }
952 977
     
953 978
     [self.view addSubview:container];
@@ -1002,7 +1027,8 @@ - (UIViewController *)popViewControllerAnimated:(BOOL)animated; {
1002 1027
         if (animated) { // kPSSVStackAnimationDuration
1003 1028
             [UIView animateWithDuration:kPSSVStackAnimationPopDuration delay:0.f options:UIViewAnimationOptionBeginFromCurrentState animations:^(void) {
1004 1029
                 lastController.containerView.alpha = 0.f;
1005  
-                lastController.containerView.transform = CGAffineTransformMakeScale(0.8, 0.8); // make smaller while fading out
  1030
+                if (enableScalingFadeInOut_)
  1031
+                    lastController.containerView.transform = CGAffineTransformMakeScale(0.8, 0.8); // make smaller while fading out
1006 1032
             } completion:^(BOOL finished) {
1007 1033
                 // even with duration = 0, this doesn't fire instantly but on a future runloop with NSFireDelayedPerform, thus ugly double-check
1008 1034
                 if (finished) {
@@ -1346,6 +1372,12 @@ - (NSUInteger)expandStack:(NSInteger)steps animated:(BOOL)animated; { // (---> d
1346 1372
     return steps; 
1347 1373
 }
1348 1374
 
  1375
+- (void)setNumberOfTouches:(NSUInteger)numberOfTouches
  1376
+{
  1377
+    numberOfTouches_ = numberOfTouches;
  1378
+    [self configureGestureRecognizer];
  1379
+}
  1380
+
1349 1381
 - (void)setLeftInset:(NSUInteger)leftInset {
1350 1382
     [self setLeftInset:leftInset animated:NO];
1351 1383
 }

0 notes on commit 1dcbed1

Please sign in to comment.
Something went wrong with that request. Please try again.