ios – How do I create popover menu?

0
65


I wish to create a settings menu like in Apple Books app. I believe the easiest way to do that job is to make use of a PopoverContentController with a StackView inside. However I’ve a couple of issues.

first downside:

If I exploit the default PopoverContentController, I see the arrow, however there isn’t any arrow in my picture. I exploit this line to take away the route of the arrow:

popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.init(rawValue: 0)

However on this case I do not see the PopoverContentController clean down open animation as a result of I eliminated the arrow. The right way to repair it?

second downside:

To get the menu like within the instance picture, I must take away the background to see the space between the weather. I am making an attempt to make use of this code

popoverPresentationController.backgroundColor = .celar

or this:

view.backgroundColor = .celar

This does not assist me. I see blur background. The right way to repair it?

full code:

 let popoverContentController = MenuVC()
 popoverContentController.modalPresentationStyle = .popover

 let popoverPresentationController = popoverContentController.popoverPresentationController
 popoverPresentationController?.permittedArrowDirections = .up
 popoverPresentationController?.sourceView = self.view
 popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.init(rawValue: 0)
        
 popoverContentController.preferredContentSize = CGSize(width: 250, peak: 250)
 popoverPresentationController?.delegate = self
        
 popoverPresentationController?.sourceRect = CGRect(
      x: self.rightStackView.body.origin.x + self.rightStackView.arrangedSubviews[0].body.origin.x + (rightBarButtonWidth/2),
      y: self.rightStackView.body.origin.y + self.rightStackView.arrangedSubviews[0].body.origin.y + (rightBarButtonHeight),
      width: 0,
      peak: 0)
        
 current(popoverContentController, animated: true, completion: nil)

enter image description here