Created
April 19, 2011 02:21
-
-
Save incanus/926686 to your computer and use it in GitHub Desktop.
live move of UIPopoverController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check that popover won't try to move off-screen; dismiss if so | |
// | |
CGFloat pX = newAttachPoint.x; | |
CGFloat pY = newAttachPoint.y; | |
CGFloat pWidth = balloon.popoverContentSize.width; | |
CGFloat pHeight = balloon.popoverContentSize.height; | |
CGFloat mWidth = map.bounds.size.width; | |
CGFloat mHeight = map.bounds.size.height; | |
UIPopoverArrowDirection d = balloon.popoverArrowDirection; | |
CGFloat threshold = 20; | |
CGFloat arrowSize = 30; | |
if (d == UIPopoverArrowDirectionRight && pX > mWidth - threshold || // popup on left hitting right edge of map | |
d == UIPopoverArrowDirectionRight && pX - arrowSize - pWidth - threshold < 0 || // popup on left hitting left edge of map | |
d == UIPopoverArrowDirectionLeft && pX > mWidth - pWidth - arrowSize - threshold || // popup on right hitting right edge of map | |
d == UIPopoverArrowDirectionLeft && pX < threshold || // popup on right hitting left edge of map | |
d == UIPopoverArrowDirectionDown && pY > mHeight - threshold || // popup on top hitting bottom edge of map | |
d == UIPopoverArrowDirectionDown && pY - pHeight - arrowSize < threshold || // popup on top hitting top edge of map | |
d == UIPopoverArrowDirectionUp && pY + arrowSize + pHeight > mHeight - threshold || // popup on bottom hitting bottom edge of map | |
d == UIPopoverArrowDirectionUp && pY < threshold || // popup on bottom hitting top edge of map | |
d == UIPopoverArrowDirectionRight && pY - (pHeight / 2) < threshold || // popup on left hitting top edge of map | |
d == UIPopoverArrowDirectionRight && pY + (pHeight / 2) > mHeight - threshold || // popup on left hitting bottom edge of map | |
d == UIPopoverArrowDirectionLeft && pY - (pHeight / 2) < threshold || // popup on right hitting top edge of map | |
d == UIPopoverArrowDirectionLeft && pY + (pHeight / 2) > mHeight - threshold || // popup on right hitting bottom edge of map | |
d == UIPopoverArrowDirectionDown && pX + (pWidth / 2) > mWidth - threshold || // popup on top hitting right edge of map | |
d == UIPopoverArrowDirectionDown && pX - (pWidth / 2) < threshold || // popup on top hitting left edge of map | |
d == UIPopoverArrowDirectionUp && pX - (pWidth / 2) < threshold || // popup on bottom hitting left edge of map | |
d == UIPopoverArrowDirectionUp && pX + (pWidth / 2) > mWidth - threshold) // popup on bottom hitting rigth edge of map | |
[balloon dismissPopoverAnimated:NO]; | |
else | |
[balloon presentPopoverFromRect:CGRectMake(newAttachPoint.x, newAttachPoint.y, 1, 1) | |
inView:map | |
permittedArrowDirections:balloon.popoverArrowDirection | |
animated:NO]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment