2

Using UIPopoverPresentationController to present a view controller in a popup, you can define permittedArrowDirections property to restrict the popup positioning possibilities. We can define multiple directions using | operator :

presentationController.permittedArrowDirections = UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp;

I know that the controller will automatically choose one the those directions, according to available space.

But is it possible to define order priority ? In that way : if there is enough space for both directions A and B, use A in priority.

I've tried to reverse the order of UIPopoverArrowDirectionDown and UIPopoverArrowDirectionUp, but it seems to always prioritize on UIPopoverArrowDirectionDown.

Does anybody has an idea to achieve this ?

AnthoPak
  • 4,191
  • 3
  • 23
  • 41

1 Answers1

2

I don't think so, the permittedArrowDirections is a OptionSet which is a bitmask under the hood. I would recommend you to some math to calculate is there enough space to display on top and pass in one value based on that.

congsun
  • 144
  • 5
  • I was hoping there were an easier solution than calculating, but as others and you suggest, it doesn't seem to be the case. If nobody provides another solution I'll go with this solution :) – AnthoPak Apr 26 '18 at 14:59
  • The math should not be that hard, basically you should know the `preferredContentSize` for your popover, and you add the size for the arrow (which is a constant value if you use the default popoverPresentationVC) and you can use the center point of your source view to check if the `y` would be good enough to show up/down, and `x` to show left/right – congsun Apr 26 '18 at 15:02