Permalink
Browse files

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

…e stack.
  • Loading branch information...
1 parent b5c56b6 commit 164d22bc91e6cab69940b5bcf66cf173c02cc064 Marcel Ball committed Jan 20, 2012
Showing with 14 additions and 2 deletions.
  1. +14 −2 PSStackedView/PSStackedViewController.m
@@ -378,7 +378,7 @@ - (CGFloat)nearestValidFloatIndex:(CGFloat)floatIndex {
}
- (CGFloat)nextFloatIndex:(CGFloat)floatIndex {
- CGFloat nextFloat = 0.f;
+ CGFloat nextFloat = floatIndex;
CGFloat roundedFloat = [self nearestValidFloatIndex:floatIndex];
CGFloat viewControllerCount = [self.viewControllers count];
for (CGFloat tester = roundedFloat + 0.5f; tester < viewControllerCount; tester += 0.5f) {
@@ -391,7 +391,7 @@ - (CGFloat)nextFloatIndex:(CGFloat)floatIndex {
}
- (CGFloat)prevFloatIndex:(CGFloat)floatIndex {
- CGFloat prevFloat = 0.f;
+ CGFloat prevFloat = floatIndex;
CGFloat roundedFloat = [self nearestValidFloatIndex:floatIndex];
for (CGFloat tester = roundedFloat - 0.5f; tester >= 0.f; tester -= 0.5f) {
if ([self isValidFloatIndex:tester]) {
@@ -428,6 +428,18 @@ - (NSArray *)rectsForControllers {
CGRect currentRect = CGRectMake(leftPos, currentVC.containerView.top, currentVC.containerView.width, currentVC.containerView.height);
[frames addObject:[NSValue valueWithCGRect:currentRect]];
}];
+ [self.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ if(idx < floatIndex && idx < [self.viewControllers count] - 1) {
+ CGRect crect = [[frames objectAtIndex:idx] CGRectValue];
+ CGRect nrect = [[frames objectAtIndex:idx + 1] CGRectValue];
+
+ CGFloat lpos = nrect.origin.x - crect.size.width;
+ lpos = MAX(lpos, [self currentLeftInset]);
+
+ CGRect newrect = CGRectMake(lpos, crect.origin.y, crect.size.width, crect.size.height);
+ [frames replaceObjectAtIndex:idx withObject:[NSValue valueWithCGRect:newrect]];
+ }
+ }];
return frames;
}

0 comments on commit 164d22b

Please sign in to comment.