我最初在xcode 10中开发了应用程序,但是我已经升级到xcode 11,然后Loader没有隐藏下面的代码
import UIKit
class LoadingView: UIView {
//MARK: IndicatoreShow
class func Show() {
DispatchQueue.main.async {
let loadingView = LoadingView(frame: UIScreen.main.bounds)
loadingView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.8)
if let _lastWindow = UIApplication.shared.windows.last {
if !_lastWindow.subviews.contains(where: { $0 is LoadingView }) {
_lastWindow.endEditing(true)
_lastWindow.addSubview(loadingView)
}
}
loadingView.addFadeAnimationWithFadeType(.fadeIn)
let indicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
indicator.center = loadingView.center
indicator.tintColor = .white
if UI_USER_INTERFACE_IDIOM() == .pad {
indicator.style = .whiteLarge
} else {
indicator.style = .white
}
indicator.startAnimating()
loadingView.addSubview(indicator)
}
}
//MARK: IndicatoreHide
class func Hide() {
DispatchQueue.main.async {
if let _lastWindow = UIApplication.shared.windows.last {
for subview in _lastWindow.subviews {
if let loadingView = subview as? LoadingView {
loadingView.addFadeAnimationWithFadeType(.fadeOut)
}
}
}
}
}
}
//MARK: Animation Enum
enum FadeType {
case fadeIn
case fadeOut
}
extension UIView {
//MARK: AnimationWith Fade
func addFadeAnimationWithFadeType(_ fadeType: FadeType) {
switch fadeType {
//MARK: fade IN
case .fadeIn:
DispatchQueue.main.async {
self.alpha = 0.0
UIView.animate(withDuration: 0.5, animations: { () -> Void in
self.alpha = 1.0
})
}
//MARK: Fade Out
case .fadeOut:
UIView.animate(withDuration: 0.5, animations: { () -> Void in
DispatchQueue.main.async {
self.alpha = 0.0
}
}, completion: { (finished) -> Void in
if finished {
self.removeFromSuperview()
}
})
}
}
}
我曾经 LoadingView.Show()//正在工作 LoadingView.Hide()//在iOS 13中不起作用 我应该更改代码什么,因为许多代码无法在iOS 13中正常工作,例如状态栏背景颜色
答案 0 :(得分:1)
在您发布的代码中,“淡出”块如下所示:
//MARK: Fade Out
case .fadeOut:
UIView.animate(withDuration: 0.5, animations: { () -> Void in
DispatchQueue.main.async {
self.alpha = 0.0
}
}, completion: { (finished) -> Void in
if finished {
self.removeFromSuperview()
}
})
}
在DispatchQueue.main.async
中包装的仅 行代码为self.alpha = 0.0
。其他所有内容都将在调用它的线程上执行。
将该案例更改为:
//MARK: Fade Out
case .fadeOut:
DispatchQueue.main.async {
UIView.animate(withDuration: 0.5, animations: { () -> Void in
self.alpha = 0.0
}, completion: { (finished) -> Void in
if finished {
self.removeFromSuperview()
}
})
}
}
可能会解决问题。