I've app initially developed in xcode 10 but I've upgrade to xcode 11 then Loader not hiding check below code
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()
}
})
}
}
}
And I used LoadingView.Show() //this is working LoadingView.Hide() // this is not working in iOS 13 What should I change in code because many code are not working in iOS 13 like status bar background color
In the code you posted, your "fade out" block looks like this:
//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()
}
})
}
There, the only line of code wrapped in DispatchQueue.main.async
is self.alpha = 0.0
. Everything else will be executed on the thread from which it was called.
Changing that case to:
//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()
}
})
}
}
will likely solve the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.