Hero
Hero copied to clipboard
HeroModifier `delay(_:)` is not working
What did you do?
// ViewController 1
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.view.addSubview(self.view1)
self.isHeroEnabled = true
}
@IBAction func onTap(_ sender: UIButton) {
let vc = ViewController2()
vc.isHeroEnabled = true
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true)
}
lazy var view1: UIView = {
let view = UIView()
view.heroID = "view"
view.heroModifiers = [.delay(0.5)]
view.bounds.size = CGSize(width: 100, height: 100)
view.center = CGPoint(x: 100, y: 300)
view.backgroundColor = .red
return view
}()
}
// ViewController 2
class ViewController2: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.view.addSubview(self.view1)
self.view.addSubview(self.button)
self.view.backgroundColor = .white
}
lazy var view1: UIView = {
let view = UIView()
view.heroID = "view"
view.heroModifiers = [.delay(0.5)]
view.bounds.size = CGSize(width: 400, height: 400)
view.center = CGPoint(x: 200, y: 200)
view.backgroundColor = .blue
return view
}()
lazy var button: UIButton = {
let b = UIButton(type: .system)
b.frame = CGRect(x: 20, y: 300, width: 100, height: 30)
b.setTitle("Back", for: .normal)
b.addTarget(self, action: #selector(onTap(_:)), for: .touchUpInside)
return b
}()
@objc func onTap(_ sender: UIButton) {
self.dismiss(animated: true)
}
}
What did you expect to happen?
Transition vc1's view to vc2's view by size and position after 0.5s delay.
What happened instead?
Size changes with no delay, and position changes with delay.
https://user-images.githubusercontent.com/33758521/188190980-3cdb12f5-15ab-4b96-952c-fc510f0dcc47.mov
General Information
-
Hero Version: develop branch
-
iOS Version(s): 15.5
-
Swift Version: 5.6
-
Devices/Simulators: iPhone 13 Pro
-
Reproducible in Examples? (Yes/No): Yes
Demo Project
It may be caused by snapshotView(afterScreenUpdates: true)
https://stackoverflow.com/a/35182128/8220957
Stack OverflowI am trying to perform an animation on a label where a flip animation happens and after it is done and after a delay, The text of the label changes.It seems that the delay never happens. The text
HeroModifier useScaleBasedSizeChange
can solve this.