I try to use custom transition animation:https://github.com/AladinWay/TransitionButton
It works as it was intended, but for some reason, after switching to a new VC application, it stops. and displays the error "Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"
I successfully localized the problem to the line
DispatchQueue.main.async {
self.collectionView.reloadData ()
}
without animation in the direct transition to VC problems arise. information is loaded and updated by reloading the view.
Perhaps the problem occurs during a direct transition to
self.present (secondVC, animated: true, completion: nil)
I tried to delete the self.collectionView.reloadData () line then the error does not occur. It just remains a black screen. But this is also a problem.
At first, I thought that the problem was with the pod, but I think that the problem is that there is a direct transition to the VC and the CollectionView just does not load, and when I try to upgrade, I get an error
import TransitionButton
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var searchTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func buttonAction(_ button: TransitionButton) {
button.startAnimation() // 2: Then start the animation when the user tap the button
let qualityOfServiceClass = DispatchQoS.QoSClass.background
let backgroundQueue = DispatchQueue.global(qos: qualityOfServiceClass)
backgroundQueue.async(execute: {
sleep(3) // 3: Do your networking task or background work here.
DispatchQueue.main.async(execute: { () -> Void in
// 4: Stop the animation, here you have three options for the `animationStyle` property:
// .expand: useful when the task has been compeletd successfully and you want to expand the button and transit to another view controller in the completion callback
// .shake: when you want to reflect to the user that the task did not complete successfly
// .normal
button.stopAnimation(animationStyle: .expand, completion: {
let secondVC = CarInfo()
self.present(secondVC, animated: true, completion: nil)
})
})
})
}
}
import TransitionButton
import UIKit
class CarInfo: CustomTransitionViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var testSegue: UILabel!
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// create post request
DispatchQueue.main.async {
self.collectionView.reloadData()
}
} catch {
print(error)
}
}
task.resume()
}
I plan to use this animation and in the background to load data from the API after displaying the finished page. But now everything just breaks