Skip to content
This repository
Browse code

Prevent it from leaving gaps when using narrow view controllers on th…

…e stack.
  • Loading branch information...
commit 164d22bc91e6cab69940b5bcf66cf173c02cc064 1 parent b5c56b6
authored January 20, 2012

Showing 1 changed file with 14 additions and 2 deletions. Show diff stats Hide diff stats

  1. 16  PSStackedView/PSStackedViewController.m
16  PSStackedView/PSStackedViewController.m
@@ -378,7 +378,7 @@ - (CGFloat)nearestValidFloatIndex:(CGFloat)floatIndex {
378 378
 }
379 379
 
380 380
 - (CGFloat)nextFloatIndex:(CGFloat)floatIndex {
381  
-    CGFloat nextFloat = 0.f;
  381
+    CGFloat nextFloat = floatIndex;
382 382
     CGFloat roundedFloat = [self nearestValidFloatIndex:floatIndex];
383 383
     CGFloat viewControllerCount = [self.viewControllers count];
384 384
     for (CGFloat tester = roundedFloat + 0.5f; tester < viewControllerCount;  tester += 0.5f) {
@@ -391,7 +391,7 @@ - (CGFloat)nextFloatIndex:(CGFloat)floatIndex {
391 391
 }
392 392
 
393 393
 - (CGFloat)prevFloatIndex:(CGFloat)floatIndex {
394  
-    CGFloat prevFloat = 0.f;
  394
+    CGFloat prevFloat = floatIndex;
395 395
     CGFloat roundedFloat = [self nearestValidFloatIndex:floatIndex];
396 396
     for (CGFloat tester = roundedFloat - 0.5f; tester >= 0.f;  tester -= 0.5f) {
397 397
         if ([self isValidFloatIndex:tester]) {
@@ -428,6 +428,18 @@ - (NSArray *)rectsForControllers {
428 428
         CGRect currentRect = CGRectMake(leftPos, currentVC.containerView.top, currentVC.containerView.width, currentVC.containerView.height);
429 429
         [frames addObject:[NSValue valueWithCGRect:currentRect]];
430 430
     }];
  431
+    [self.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  432
+        if(idx < floatIndex && idx < [self.viewControllers count] - 1) {
  433
+            CGRect crect = [[frames objectAtIndex:idx] CGRectValue];
  434
+            CGRect nrect = [[frames objectAtIndex:idx + 1] CGRectValue];
  435
+            
  436
+            CGFloat lpos = nrect.origin.x - crect.size.width;
  437
+            lpos = MAX(lpos, [self currentLeftInset]);
  438
+            
  439
+            CGRect newrect = CGRectMake(lpos, crect.origin.y, crect.size.width, crect.size.height);
  440
+            [frames replaceObjectAtIndex:idx withObject:[NSValue valueWithCGRect:newrect]];
  441
+        }
  442
+    }];
431 443
     
432 444
     return frames;
433 445
 }

0 notes on commit 164d22b

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