gpt4 book ai didi

ios - iPhone ios 上的 swift 3 中的弹出窗口

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

我正在尝试使用以下代码制作弹出菜单:

import UIKit

class BeobachtungViewController: UIViewController, UIPopoverPresentationControllerDelegate {


@IBAction func addClicked(_ sender: AnyObject) {
// get a reference to the view controller for the popover
let popController = UIStoryboard(name: "Personenakte", bundle: nil).instantiateViewController(withIdentifier: "popoverId")

// set the presentation style
popController.modalPresentationStyle = UIModalPresentationStyle.popover

// set up the popover presentation controller
popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up
popController.popoverPresentationController?.delegate = self
popController.popoverPresentationController?.sourceView = sender as! UIView // button
popController.popoverPresentationController?.sourceRect = sender.bounds

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

// UIPopoverPresentationControllerDelegate method
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
// Force popover style
return UIModalPresentationStyle.none
}
}

这适用于 iPad,但在 iPhone 上,弹出窗口会占据整个 iPhone 屏幕。我只想要一个带有箭头的小窗口。我找到了几个教程,但没有一个对我有用。

最佳答案

将您的委托(delegate)方法更改为:

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

关于ios - iPhone ios 上的 swift 3 中的弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53690345/

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