Swift iOS - 如何将 UIPopoverBackgroundView Class 中的方法连接到不同 class 中的 PopoverController?
Swift iOS -How to connect method in UIPopoverBackgroundView Class to a PopoverController in a different class?
我正在使用 PopoverController,我想去除背景阴影。 Apple 说要将 UIPopoverBackgroundView 和 return false
子类化为 override class var wantsDefaultContentAppearance: Bool { get }
我将它子类化并将布尔值设置为 false
但阴影仍然显示。如何将此子类连接到我在 LogoutClass 的 Actionsheet 中使用的 PopoverController?
UIPopoverBackgroundView 子类:
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
实例的 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
.
我正在使用 PopoverController,我想去除背景阴影。 Apple 说要将 UIPopoverBackgroundView 和 return false
子类化为 override class var wantsDefaultContentAppearance: Bool { get }
我将它子类化并将布尔值设置为 false
但阴影仍然显示。如何将此子类连接到我在 LogoutClass 的 Actionsheet 中使用的 PopoverController?
UIPopoverBackgroundView 子类:
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
实例的 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 .