gpt4 book ai didi

ios - Swift iOS - 如何将 UIPopoverBackgroundView 类中的方法连接到不同类中的 PopoverController?

转载 作者:搜寻专家 更新时间:2023-11-01 06:16:08 26 4
gpt4 key购买 nike

我正在使用 PopoverController,我想去掉背景阴影。 Apple 说要对 UIPopoverBackgroundView 进行子类化并为 override class var wantsDefaultContentAppearance: Bool { get }

返回 false

https://developer.apple.com/documentation/uikit/uipopoverbackgroundview/1619357-wantsdefaultcontentappearance

我将它子类化并将 bool 设置为 false 但阴影仍然显示。如何将此子类连接到我在 LogoutClass 的 Actionsheet 中使用的 PopoverController?

UIPopoverBackgroundView 子类:

class PopoverBackgroundView: UIPopoverBackgroundView {

override class var wantsDefaultContentAppearance: Bool {
get {
return false
}
}
}

注销 Controller :

class LogoutController:UIViewController{

fileprivate func logOff(){

let actionSheet = UIAlertController(title: nil, message: "Logging out?", preferredStyle: .actionSheet)

let logout = UIAlertAction(title: "Log Out", style: .default){
(action) in
//bla bla bla
}

actionSheet.addAction(logout)

if let popoverController = actionSheet.popoverPresentationController{
popoverController.sourceView = view
guard let window = UIApplication.shared.keyWindow else { return }
window.backgroundColor = .clear
popoverController.sourceRect = CGRect(x:window.bounds.midX, y:window.bounds.midY, width:0, height:0)
popoverController.permittedArrowDirections = []

}
present(actionSheet, animated: true, completion: nil)
}
}

最佳答案

您必须像这样设置 UIPopoverPresentationController 实例的 popoverBackgroundViewClass 属性:

objective-c :

popoverController.popoverBackgroundViewClass = [PopoverBackgroundView class];

swift

popoverController?.popoverBackgroundViewClass = PopoverBackgroundView.self

根据 Apple 文档:

The default value of this property is nil, which causes the presentation controller to use the default popover appearance. Setting this property to a value other than nil causes the presentation controller to use the specified class to draw the popover’s background content. The class you specify must be a subclass of UIPopoverBackgroundView .

关于ios - Swift iOS - 如何将 UIPopoverBackgroundView 类中的方法连接到不同类中的 PopoverController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44691501/

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