[英]How hide blur for UIPopoverPresentationController in swift?
I've implemented popover for UIButton:我已经为 UIButton 实现了弹出框:
@objc func showList(sender: AnyObject?) {
guard let buttonView = sender?.value(forKey: "view") as? UIButton else { return }
guard let popVC = R.storyboard.first.VC() else { return }
popVC.modalPresentationStyle = .popover
let popOverVC = popVC.popoverPresentationController
popOverVC?.delegate = self
popOverVC?.sourceView = buttonView
popOverVC?.sourceRect = CGRect(x: 0, y: 190, width: 0, height: 0)
popOverVC?.permittedArrowDirections = .init(rawValue: 0)
popVC.preferredContentSize = CGSize(width: 150, height: 250)
showedViewController.present(popVC, animated: true, completion: nil)
}
extension VCInteractor: UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
}
It's working good, but I need one fix - I want to hide UIVisualEffectBackdropView
for my popover (it's like blur under my UITableViewController).它工作得很好,但我需要一个修复 - 我想为我的弹出框隐藏UIVisualEffectBackdropView
(它就像我的 UITableViewController 下的模糊)。 So, I can't find any info how to disable (hide) this blur, do you have any ideas?所以,我找不到任何信息如何禁用(隐藏)这种模糊,你有什么想法吗?
I've fixed my issue with my custom class我已经解决了我的自定义课程的问题
class PopoverBackgroundView: UIPopoverBackgroundView {
override init(frame: CGRect) {
super.init(frame: frame)
self.layer.shadowColor = UIColor.clear.cgColor
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override static func contentViewInsets() -> UIEdgeInsets {
return UIEdgeInsets.zero
}
override static func arrowHeight() -> CGFloat {
return 0
}
override var arrowDirection: UIPopoverArrowDirection {
get { return UIPopoverArrowDirection.down }
set {
setNeedsLayout()
}
}
override var arrowOffset: CGFloat {
get { return 0 }
set {
setNeedsLayout()
}
}
}
and I've added it like that我已经这样添加了
popOverVC?.popoverBackgroundViewClass = PopoverBackgroundView.self
that's all仅此而已
here i have a very simple solution.在这里,我有一个非常简单的解决方案。
let appearance = UIVisualEffectView.appearance(whenContainedInInstancesOf: [NSClassFromString("_UIPopoverStandardChromeView")! as! UIAppearanceContainer.Type])
appearance.effect = UIVisualEffect()
add the code to the AppDelegate.swift file or anywhere the app is getting initialized.将代码添加到 AppDelegate.swift 文件或应用程序正在初始化的任何地方。
I suggest adding this to the PopoverBackgroundView that Vadim Nikolaev has posted above.我建议将此添加到 Vadim Nikolaev 在上面发布的 PopoverBackgroundView 中。 This removes the "clear halo" effect when removing the blur.这会在消除模糊时消除“清晰光晕”效果。
`override func didMoveToWindow() {
super.didMoveToWindow()
if #available(iOS 13, *) {
// iOS 13 (or newer)
if let window = UIApplication.shared.keyWindow {
let transitionViews = window.subviews.filter { String(describing: type(of: $0)) == "UITransitionView" }
for transitionView in transitionViews {
let shadowView = transitionView.subviews.filter { String(describing: type(of: $0)) == "_UICutoutShadowView" }.first
shadowView?.isHidden = true
}
}
}
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.