我正在使用一个PopoverController,我想摆脱背景阴影。苹果说subClass UIPopoverBackgroundView和返回false给override class var wantsDefaultContentAppearance: Bool { get }
我将其子类化,并将bool设置为false,但阴影仍然显示。如何将这个子类连接到我在LogoutClass中的Actionsheet中使用的LogoutClass?
UIPopoverBackgroundView子类:
class PopoverBackgroundView: UIPopoverBackgroundView {
override class var wantsDefaultContentAppearance: Bool {
get {
return false
}
}
}LogoutController:
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)
}
}发布于 2017-06-22 06:49:03
您必须设置popoverBackgroundViewClass实例的UIPopoverPresentationController属性,如下所示:
目标C :
popoverController.popoverBackgroundViewClass = [PopoverBackgroundView class];Swift
popoverController?.popoverBackgroundViewClass = PopoverBackgroundView.self根据苹果的文档:
此属性的默认值为零,这将导致表示控制器使用默认的popover外观。将此属性设置为0以外的值将导致表示控制器使用指定的类绘制popover的背景内容。您指定的类必须是UIPopoverBackgroundView的子类。
https://stackoverflow.com/questions/44691501
复制相似问题