HeroTransitions / Hero

Elegant transition library for iOS & tvOS

Home Page:https://HeroTransitions.github.io/Hero/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HeroModifier `delay(_:)` is not working

cloxnu opened this issue · comments

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.

2022-09-02.23.45.45.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

HeroDemo.zip

It may be caused by snapshotView(afterScreenUpdates: true)

https://stackoverflow.com/a/35182128/8220957

Stack Overflow
I 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.