HeroTransitions / Hero

Elegant transition library for iOS & tvOS
https://HeroTransitions.github.io/Hero/
MIT License
22k stars 1.72k forks source link

HeroModifier `delay(_:)` is not working #744

Closed cloxnu closed 1 year ago

cloxnu commented 1 year ago

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

Demo Project

HeroDemo.zip

cloxnu commented 1 year ago

It may be caused by snapshotView(afterScreenUpdates: true)

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

Stack Overflow
UIView's animateWithDuration delay not delaying animation
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
cloxnu commented 1 year ago

HeroModifier useScaleBasedSizeChange can solve this.