iPhone popup menu like iPad popover?

前端 未结 8 2216
醉话见心
醉话见心 2020-11-27 02:58

How can i implement this popup menu in iphone app like a popover in ipad?

\"alt


ED

8条回答
  •  清酒与你
    2020-11-27 03:38

    To get a popover from a right side bar button item on a navigation controller that is part of a tableview controller, the following worked for me for Swift 4 and Xcode 9.

    1. Follow the steps in Suragch answer above (as edited by the Community.)
    2. Do not implement the Segue as shown in the answer above. For some reason, the segue causes the popover to go full screen despite setting the explicit size.
    3. Give your popover view controller a title in Attributes Inspector
    4. Add the following code in the TableView controller where the popup will show.
    5. Modify the string identifier (the one here is referencing a Constant.swift file)
    6. Modify "as! FilterVC" to use the title of the your popover view controller.

      /// Shows a filter popover view
      @IBAction func filterBtnPressed(_ sender: UIBarButtonItem) {
          let popover = storyboard?.instantiateViewController(withIdentifier: FILTER_VC) as! FilterVC
          popover.modalPresentationStyle = UIModalPresentationStyle.popover
          popover.popoverPresentationController?.backgroundColor = UIColor.green
          popover.popoverPresentationController?.delegate = self
          popover.popoverPresentationController?.backgroundColor = ColorPalette.Blue.Medium
          popover.popoverPresentationController?.sourceView = self.view
          popover.popoverPresentationController?.sourceRect = CGRect(x: self.view!.bounds.width, y: 0, width: 0, height: 0)
          popover.popoverPresentationController?.permittedArrowDirections = .up
          self.present(popover, animated: true)
      } }
      
      
      func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
          return UIModalPresentationStyle.none
      }
      

提交回复
热议问题