Я пытаюсь использовать пользовательскую анимацию перехода: https://github.com/AladinWay/TransitionButton
Работает так, как задумывалось, но по какой-то причине после переключения на новое приложение VC останавливается. и отображает ошибку "Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"
Я успешно локализовал проблему в строке
DispatchQueue.main.async {
self.collectionView.reloadData ()
}
без анимации при прямом переходе на ВК возникают проблемы. информация загружается и обновляется путем перезагрузки представления.
Возможно, проблема возникает во время прямого перехода к
self.present (secondVC, animated: true, completion: nil)
Я пытался удалить строку self.collectionView.reloadData ()
тогда ошибка не возникает. Просто остается черный экран.
Но это тоже проблема.
Сначала я думал, что проблема была в модуле, но я думаю, что проблема в том, что существует прямой переход к VC, и CollectionView просто не загружается, и когда я пытаюсь обновить, я получаю ошибка
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()
}
Я планирую использовать эту анимацию и в фоновом режиме для загрузки данных из API после отображения готовой страницы.
Но сейчас все просто ломается