UIPopoverArrowDirection.down不适用于iOS

时间:2018-03-21 09:37:12

标签: ios swift uipopovercontroller

enter image description here我试图在我的Tabbarview控制器上显示带有向下箭头的popover viewcontroller,但是如果我选择关闭它会停止显示,如果是up,它会显示。

所以我的问题是

1)如果UIPopoverArrowDirection.down不起作用,如何向下箭头?为什么它不起作用?

2)如何调试并找到无法显示错误的错误,没有为此打印日志。

3)如何在不在侧面的视图中心显示箭头。

我的代码是,

 let popController = UIStoryboard(name: kStoryboard.login, bundle: nil).instantiateViewController(withIdentifier: "popoverId")

        popController.modalPresentationStyle = UIModalPresentationStyle.popover
        popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down
        popController.popoverPresentationController?.backgroundColor = UIColor.Text.orange
        popController.popoverPresentationController?.delegate = self
        popController.popoverPresentationController?.sourceView = self.view
        popController.popoverPresentationController?.sourceRect = CGRect(x: 0, y: 0, width: 100, height: 100)

        // present the popover
        self.present(popController, animated: true, completion: nil)




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

我从故事板中给出了preferredcontentsize。

1 个答案:

答案 0 :(得分:0)

问题是目前您没有提供sourceView + preferredContentSize

import UIKit

class ViewController: UIViewController , UIPopoverPresentationControllerDelegate{

    @IBOutlet weak var aa: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()


     }

    override func viewDidAppear(_ animated: Bool)
    { 

      let popController = UIStoryboard(name:"Main", bundle: nil).instantiateViewController(withIdentifier: "popoverId")
      popController.modalPresentationStyle = UIModalPresentationStyle.popover
      popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down
      popController.popoverPresentationController?.backgroundColor = UIColor.red
      popController.popoverPresentationController?.delegate = self
      popController.popoverPresentationController?.sourceView = self.aa
      popController.popoverPresentationController?.sourceRect = CGRect(x: 20, y: 20, width: 100, height: 100)

      popController.preferredContentSize = CGSize.init(width: 200, height: 200)
    // present the popover
     self.present(popController, animated: true, completion: nil)



    }

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

}

enter image description here