Skip to content
Browse files

Fixed positioning issues of popover

  • Loading branch information...
1 parent 2bd05b5 commit 36c8874d81ac33c1e92b24cb83a91c23da80bab4 @werner77 committed May 8, 2011
Showing with 25 additions and 8 deletions.
  1. +15 −4 Classes/WEPopoverContainerView.m
  2. +10 −4 Classes/WEPopoverTableViewController.m
View
19 Classes/WEPopoverContainerView.m
@@ -155,7 +155,8 @@ - (void)determineGeometryForSize:(CGSize)theSize anchorRect:(CGRect)anchorRect d
arrowRect = CGRectZero;
arrowDirection = UIPopoverArrowDirectionUnknown;
- CGFloat biggestSurface = 0.0;
+ CGFloat biggestSurface = 0.0f;
+ CGFloat currentMinMargin = 0.0f;
UIImage *upArrowImage = [UIImage imageNamed:properties.upArrowImageName];
UIImage *downArrowImage = [UIImage imageNamed:properties.downArrowImageName];
@@ -276,16 +277,26 @@ - (void)determineGeometryForSize:(CGSize)theSize anchorRect:(CGRect)anchorRect d
break;
}
-
- CGRect intersection = CGRectIntersection(displayArea, CGRectOffset(theBgRect, theOffset.x, theOffset.y));
+ CGRect bgFrame = CGRectOffset(theBgRect, theOffset.x, theOffset.y);
+ CGRect intersection = CGRectIntersection(displayArea, bgFrame);
CGFloat surface = intersection.size.width * intersection.size.height;
- if (surface > biggestSurface) {
+ CGFloat minMarginLeft = CGRectGetMinX(bgFrame) - CGRectGetMinX(displayArea);
+ CGFloat minMarginRight = CGRectGetMaxX(displayArea) - CGRectGetMaxX(bgFrame);
+ CGFloat minMarginTop = CGRectGetMinY(bgFrame) - CGRectGetMinY(displayArea);
+ CGFloat minMarginBottom = CGRectGetMaxY(displayArea) - CGRectGetMaxY(bgFrame);
+
+ CGFloat minMargin = MIN(minMarginLeft, minMarginRight);
+ minMargin = MIN(minMargin, minMarginTop);
+ minMargin = MIN(minMargin, minMarginBottom);
+
+ if (surface >= biggestSurface && minMargin >= currentMinMargin) {
biggestSurface = surface;
offset = theOffset;
arrowRect = theArrowRect;
bgRect = theBgRect;
arrowDirection = theArrowDirection;
+ currentMinMargin = minMargin;
}
}
View
14 Classes/WEPopoverTableViewController.m
@@ -166,18 +166,23 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
if (shouldShowNewPopover) {
UIViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain];
CGRect frame = [tableView cellForRowAtIndexPath:indexPath].frame;
+ //double percentage = (rand() / ((double)RAND_MAX));
+ //double percentage = 0.95;
+ //CGRect rect = CGRectMake(frame.size.width * percentage, frame.origin.y, 1, frame.size.height);
+ CGRect rect = frame;
self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease];
self.popoverController.delegate = self;
//Uncomment the line below to allow the table view to handle events while the popover is displayed.
//Otherwise the popover is dismissed automatically if a user touches anywhere outside of its view.
- //self.popoverController.passthroughViews = [NSArray arrayWithObject:self.tableView];
+ self.popoverController.passthroughViews = [NSArray arrayWithObject:self.tableView];
- [self.popoverController presentPopoverFromRect:frame
+ [self.popoverController presentPopoverFromRect:rect
inView:self.view
- permittedArrowDirections:UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown
+ permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown|
+ UIPopoverArrowDirectionLeft|UIPopoverArrowDirectionRight)
animated:YES];
currentPopoverCellIndex = indexPath.row;
@@ -199,7 +204,8 @@ - (IBAction)showPopover:(id)sender {
self.popoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar];
[self.popoverController presentPopoverFromBarButtonItem:sender
- permittedArrowDirections:UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown
+ permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown|
+ UIPopoverArrowDirectionLeft|UIPopoverArrowDirectionRight)
animated:YES];
[contentViewController release];
} else {

0 comments on commit 36c8874

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