I'm having difficulties presenting a popup-view with a sourceView that is a UIBarbuttonItem of a UITextView's accessoryview. It seems as if views inside a Keyboard are somehow not treated the same as other views in the view-hierarchy. When I end keyboard editing, the popup-view appears on the underlaying viewcontroller's view. Here's some code:
@objc func foregroundColorPressed(button : UIBarButtonItem)
{
let colorSelectionPopup = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ColorSelectionPopup")
colorSelectionPopup.modalPresentationStyle = .popover
let popOver = colorSelectionPopup.popoverPresentationController!
colorSelectionPopup.preferredContentSize = CGSize(width: 200, height: 100)
popOver.delegate = self
popOver.permittedArrowDirections = .up
popOver.barButtonItem = button
//popOver.sourceView = button.theView
//popOver.sourceRect = (button.theView?.bounds)!
getCurrentViewController()?.present(colorSelectionPopup, animated: true, completion: {
//
})
and my popoverPresentationDelegate method is
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}
Is what I'm trying to achieve possible? Any help much appreciated!
Seemed that the problem was the arrow direction property of the popoverPresentationController. Setting that to .none or .down made the code work.