Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift iOS-如何将UIPopoverBackgroundView类中的方法连接到其他类中的PopoverController?_Ios_Swift_Uipopovercontroller_Uialertcontroller_Uiactionsheet - Fatal编程技术网

Swift iOS-如何将UIPopoverBackgroundView类中的方法连接到其他类中的PopoverController?

Swift iOS-如何将UIPopoverBackgroundView类中的方法连接到其他类中的PopoverController?,ios,swift,uipopovercontroller,uialertcontroller,uiactionsheet,Ios,Swift,Uipopovercontroller,Uialertcontroller,Uiactionsheet,我用的是PopoverController,我想去掉背景阴影。苹果公司要求对UIPopoOverBackgroundView进行子类化,并为覆盖类var wantsDefaultContentAppearance:Bool{get}返回false 我将其子类化,并将bool设置为false,但阴影仍然显示。我如何将这个子类连接到我在LogoutClass的Actionsheet中使用的PopoverController UIPopoOverBackgroundView子类: class Pop

我用的是PopoverController,我想去掉背景阴影。苹果公司要求对UIPopoOverBackgroundView进行子类化,并为
覆盖类var wantsDefaultContentAppearance:Bool{get}
返回
false

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

UIPopoOverBackgroundView子类:

class PopoverBackgroundView: UIPopoverBackgroundView {

override class var wantsDefaultContentAppearance: Bool {
        get {
            return false
        }
    }
}
注销控制器:

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
实例的
PopoOverBackgroundViewClass
属性,如下所示:

目标C:

popoverController.popoverBackgroundViewClass = [PopoverBackgroundView class];
Swift

popoverController?.popoverBackgroundViewClass = PopoverBackgroundView.self
根据苹果文档:

此属性的默认值为nil,这会导致presentation controller使用默认的popover外观。将此属性设置为非nil的值会导致presentation controller使用指定的类来绘制popover的背景内容。指定的类必须是的子类 UIPopoOverBackgroundView


您必须设置
UIPopoverPresentationController
实例的
PopoOverBackgroundViewClass
属性,如下所示:

目标C:

popoverController.popoverBackgroundViewClass = [PopoverBackgroundView class];
Swift

popoverController?.popoverBackgroundViewClass = PopoverBackgroundView.self
根据苹果文档:

此属性的默认值为nil,这会导致presentation controller使用默认的popover外观。将此属性设置为非nil的值会导致presentation controller使用指定的类来绘制popover的背景内容。指定的类必须是的子类 UIPopoOverBackgroundView


谢谢你的帮助。我试过了,但阴影仍然存在,所以我不确定它是否有效。它仍然不起作用,但你的答案是正确的。后台类实现有问题。谢谢,谢谢你的帮助。我试过了,但阴影仍然存在,所以我不确定它是否有效。它仍然不起作用,但你的答案是正确的。后台类实现有问题。谢谢