UIView.transition with delay
Asked Answered
O

2

6

I have simultaneous animations going on, and I would like to transition the VC in the middle (it will fade so it will see some of the other animations). However, I can't find documentation how to delay a transition similar to UIView.animateWithDuration.

I want to achieve this...

UIView.transition(withDuration: 0.5, delay: 0.1, options: .transitionCrossDissolve, animations: {})

I can manually add a delay like so.. but was wondering if there's a more elegant way.

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {}
Oncoming answered 17/1, 2019 at 19:57 Comment(3)
how about : UIView.animateWithDuration 0.1, animations {UIView.transition(withDuration: 0.5){. } }Alfalfa
@Alfalfa Did you just copy someone else's answer?Oncoming
That's different. He puts in completion, I put in animation block.Alfalfa
G
0

Unfortunately no. Using a bunch of UIView transitions/animations can get a little hairy.

In the past, I've resorted to setting up an NSTimer that fires 1/30 seconds and I ended up managing all the start times on my own.

What you can do is series out the animations using the closure.

UIView.animate(withDuration: 1, animations: { 
}, completion: {Do UIView transition here})
Grotto answered 17/1, 2019 at 20:17 Comment(1)
More accurately:- UIView.animate(withDuration: 1, animations: { }, completion: { (finished: Bool) in // transition here })Roye
M
0

It seems no way except surrounding with Timer:

Timer.scheduledTimer(withTimeInterval: 5, repeats: true, block: { _ in
    UIView.transition(with: self.myImageView, duration: 0.75,
                      options: [.transitionCrossDissolve],
                      animations: {
        self.myImageView.image = newImage
    })
})
Magner answered 14/11, 2022 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.