Skip to content

Commit

Permalink
Prevent it from leaving gaps when using narrow view controllers on th…
Browse files Browse the repository at this point in the history
…e stack.
  • Loading branch information
Marus committed Jan 20, 2012
1 parent b5c56b6 commit 164d22b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions PSStackedView/PSStackedViewController.m
Expand Up @@ -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) {
Expand All @@ -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]) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 164d22b

Please sign in to comment.