【发布时间】:2017-10-05 00:29:56
【问题描述】:
我正在使用UIAlertController 执行某些操作。
但我不喜欢动作组视图中的模糊视图效果(见下面的截图)。
我正在尝试消除这种模糊效果。我在网上做了一些研究,在UIAlertController 中找不到任何可以消除这种模糊效果的API。另外,根据他们的苹果文档here:
UIAlertController 类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。
我看到 Instagram 也消除了这种模糊视图效果:
我能找到删除它的唯一方法是通过UIAlertController 的扩展自己更新视图层次结构。
extension UIAlertController {
@discardableResult private func findAndRemoveBlurEffect(currentView: UIView) -> Bool {
for childView in currentView.subviews {
if childView is UIVisualEffectView {
childView.removeFromSuperview()
return true
} else if String(describing: type(of: childView.self)) == "_UIInterfaceActionGroupHeaderScrollView" {
// One background view is broken, we need to make sure it's white.
if let brokenBackgroundView = childView.superview {
// Set broken brackground view to a darker white
brokenBackgroundView.backgroundColor = UIColor.colorRGB(red: 235, green: 235, blue: 235, alpha: 1)
}
}
findAndRemoveBlurEffect(currentView: childView)
}
return false
}
}
let actionSheetController = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
actionSheetController.view.tintColor = .lightBlue
actionSheetController.removeBlurryView()
这很好,它消除了我的模糊视图效果:
我想知道...我的解决方案是实现这一目标的唯一方法吗?还是我缺少关于警报控制器外观的一些东西? 也许有一种更清洁的方法可以准确地完成这个结果?还有其他想法吗?
【问题讨论】:
-
也许 instagram 仍在使用已弃用的 UIActionSheet。私下访问 alertcontroller 可能会导致您的应用被拒绝。
标签: ios objective-c swift uialertcontroller uivisualeffectview