gpt4 book ai didi

ios - UIPopoverArrowDirection.down 不适用于 iOS

转载 作者:行者123 更新时间:2023-11-30 11:39:33 26 4
gpt4 key购买 nike

enter image description here我试图在 Tabbarview Controller 上显示带有向下箭头的弹出 View Controller ,但如果我选择向下,它就会停止出现,而如果选择向上,它就会显示。

所以我的问题是

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

2)如何调试并找到不显示的错误,没有打印任何日志。

3)如何在 View 中央而不是侧面显示箭头。

我的代码是,

 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
}

我已经从 Storyboard 中给出了首选内容大小。

最佳答案

问题是目前您没有提供 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

关于ios - UIPopoverArrowDirection.down 不适用于 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49402707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com