Skip to content

Commit

Permalink
Fixed issues werner77#10 and werner77#11 thanks to chrispix and ntamas
Browse files Browse the repository at this point in the history
  • Loading branch information
werner77 committed Jun 13, 2011
1 parent a00f354 commit 9435d1d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
48 changes: 44 additions & 4 deletions Classes/Popover/WEPopoverContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (id)initWithSize:(CGSize)theSize
properties:(WEPopoverContainerViewProperties *)theProperties {
if ((self = [super initWithFrame:CGRectZero])) {

self.properties = theProperties;
[self setProperties:theProperties];
correctedSize = CGSizeMake(theSize.width + properties.leftBgMargin + properties.rightBgMargin + properties.leftContentMargin + properties.rightContentMargin,
theSize.height + properties.topBgMargin + properties.bottomBgMargin + properties.topContentMargin + properties.bottomContentMargin);
[self determineGeometryForSize:correctedSize anchorRect:anchorRect displayArea:displayArea permittedArrowDirections:permittedArrowDirections];
Expand Down Expand Up @@ -278,18 +278,58 @@ - (void)determineGeometryForSize:(CGSize)theSize anchorRect:(CGRect)anchorRect d
}

CGRect bgFrame = CGRectOffset(theBgRect, theOffset.x, theOffset.y);
CGRect intersection = CGRectIntersection(displayArea, bgFrame);
CGFloat surface = intersection.size.width * intersection.size.height;

CGFloat minMarginLeft = CGRectGetMinX(bgFrame) - CGRectGetMinX(displayArea);
CGFloat minMarginLeft = CGRectGetMinX(bgFrame) - CGRectGetMinX(displayArea);
CGFloat minMarginRight = CGRectGetMaxX(displayArea) - CGRectGetMaxX(bgFrame);
CGFloat minMarginTop = CGRectGetMinY(bgFrame) - CGRectGetMinY(displayArea);
CGFloat minMarginBottom = CGRectGetMaxY(displayArea) - CGRectGetMaxY(bgFrame);

if (minMarginLeft < 0) {
// Popover is too wide and clipped on the left; decrease width
// and move it to the right
theOffset.x -= minMarginLeft;
theBgRect.size.width += minMarginLeft;
minMarginLeft = 0;
if (theArrowDirection == UIPopoverArrowDirectionRight) {
theArrowRect.origin.x = CGRectGetMaxX(theBgRect) - properties.rightBgMargin;
}
}
if (minMarginRight < 0) {
// Popover is too wide and clipped on the right; decrease width.
theBgRect.size.width += minMarginRight;
minMarginRight = 0;
if (theArrowDirection == UIPopoverArrowDirectionLeft) {
theArrowRect.origin.x = CGRectGetMinX(theBgRect) - leftArrowImage.size.width + properties.leftBgMargin;
}
}
if (minMarginTop < 0) {
// Popover is too high and clipped at the top; decrease height
// and move it down
theOffset.y -= minMarginTop;
theBgRect.size.height += minMarginTop;
minMarginTop = 0;
if (theArrowDirection == UIPopoverArrowDirectionDown) {
theArrowRect.origin.y = CGRectGetMaxY(theBgRect) - properties.bottomBgMargin;
}
}
if (minMarginBottom < 0) {
// Popover is too high and clipped at the bottom; decrease height.
theBgRect.size.height += minMarginBottom;
minMarginBottom = 0;
if (theArrowDirection == UIPopoverArrowDirectionUp) {
theArrowRect.origin.y = CGRectGetMinY(theBgRect) - upArrowImage.size.height + properties.topBgMargin;
}
}
bgFrame = CGRectOffset(theBgRect, theOffset.x, theOffset.y);

CGFloat minMargin = MIN(minMarginLeft, minMarginRight);
minMargin = MIN(minMargin, minMarginTop);
minMargin = MIN(minMargin, minMarginBottom);

// Calculate intersection and surface
CGRect intersection = CGRectIntersection(displayArea, bgFrame);
CGFloat surface = intersection.size.width * intersection.size.height;

if (surface >= biggestSurface && minMargin >= currentMinMargin) {
biggestSurface = surface;
offset = theOffset;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Popover/WEPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ @implementation WEPopoverController
@synthesize passthroughViews;

- (id)init {
if (self = [super init]) {
if ((self = [super init])) {
}
return self;
}
Expand Down

0 comments on commit 9435d1d

Please sign in to comment.