Swift iOS-如何将UIPopoverBackgroundView类中的方法连接到其他类中的PopoverController?
我用的是PopoverController,我想去掉背景阴影。苹果公司要求对UIPopoOverBackgroundView进行子类化,并为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
覆盖类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
谢谢你的帮助。我试过了,但阴影仍然存在,所以我不确定它是否有效。它仍然不起作用,但你的答案是正确的。后台类实现有问题。谢谢,谢谢你的帮助。我试过了,但阴影仍然存在,所以我不确定它是否有效。它仍然不起作用,但你的答案是正确的。后台类实现有问题。谢谢