2

I am trying to use UIPopoverPresentationController to display a popover that doesn't take up the whole screen. already checked this and other tutorials, but don't worked.

Here my code:

  @IBAction func temp(_ sender: UIButton) {
    let vc = UIStoryboard(name: "StayView", bundle: nil).instantiateViewController(withIdentifier: "StayViewPopOverViewController") as! StayViewPopOverViewController

    vc.modalPresentationStyle = .popover
    vc.preferredContentSize = CGSize(width: 180, height: 75)

    let popover = vc.popoverPresentationController!
    popover.sourceView = self.btnTemp
    popover.sourceRect = self.btnTemp.bounds
    popover.delegate = self
    self.present(vc, animated: true, completion: nil)
}

My delegate method:

 func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle {
    return .none
}

but that cover Whole screen.
I tried to put breakpoint on delegate method but interpreter didn't stop on that.

can anyBody have any solution or any suggetions?

Upated: I want to achieve like this:
enter image description here

Uday Babariya
  • 1,031
  • 1
  • 13
  • 31

2 Answers2

1

Finally I Got the answer.
Just need to update my delegate method like this:

 func adaptivePresentationStyle(
    for controller: UIPresentationController,
    traitCollection: UITraitCollection)
    -> UIModalPresentationStyle {
        return .none
}

Thats It... Works Great!!!

Uday Babariya
  • 1,031
  • 1
  • 13
  • 31
0

Update following lines

 vc.modalPresentationStyle = .popover
 vc.preferredContentSize = CGSize(width: 180, height: 75)

with

vc.modalPresentationStyle = .overFullScreen
vc.preferredContentSize = view.frame.size
Pravin Tate
  • 1,145
  • 8
  • 18