Reputation: 1609
I've encountered strange problem in UIPopOverController. Normally, I present popover this way:
[popoverVC presentPopoverFromRect:sender.frame
inView:sender.superview
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:NO];
However, sometimes there is no enough space on the right side of the button (sender) and the popover is displayed below the button with UIPopoverArrowDirectionUP. It make sense - if popover can't be displayed properly, controller trys to display it with different arrow.
But when I moved my button (sender) about 10 pixels to the left, popover doesn't behave this way. There is still no enough space to display it properly but it doesn't change its arrow although popover is ~20px wide so it's way too small.
Is there any way to say popovercontroller: "If popover does not have enough space to display all content, change arrow direction" ?
Upvotes: 0
Views: 3352
Reputation: 857
Why not use UIPopoverArrowDirectionAny
, which Apple recommends anyway, or, if you absolutely must, UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionUp
? The exact orientation of the popover's arrow seldom matters that much.
If that doesn't work, I guess the only choice is to do some math in the action method. (Disclaimer: I've never tried this, but I don't see why you couldn't do it if you absolutely had to.) First convert the sender's bounds to the top-level view's coordinate space. Depending on the specifics of your app's view hierarchy, you may need to convert the bounds/frame to/from an appropriate view. Unless you've got a something weird going on, this should work:
[self.view convertRect:[sender bounds] fromView:sender]
Then check whether the resulting rectangle is more than X points away from the right edge of the screen, where X is the width of the popover (including the black border and arrow). If there is enough room, present the popover as you say above. If not, use UIPopoverArrowDirectionUp instead.
Upvotes: 4