I have an app that draws names randomly and then displays them in groups of 3 or 4. All is fine, but I would like to delay the output (increase suspense) We currently get "Group 1 consists of Fred, Dave, Steve, John"
We want to see "Group 1 consists of .(pause).....Fred...(pause)......Dave..(pause)......Steve....(pause).....John"
I have tried Sleep(x)
but this seems to be ignored.
Here is my simple loop:
The players are stored in array playing
.
G1
can be anything from 1 to 4.
Gr1Text
is a textbox.
for i in 0...G1-1 {
G1Text = (G1Text ?? "") + playing[i] + " , "
self.Gr1Text.text = G1Text}
}
Just need a pause between displaying the names
thanks
So I have created some code to drop the names using animation
func dropText(_ sender: String)
{
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = sender
label.font = UIFont.systemFont(ofSize: 32, weight: .bold)
label.textColor = UIColor.white
view.addSubview(label)
var yAnchor = label.centerYAnchor.constraint(equalTo: view.topAnchor, constant: -200)
yAnchor.isActive = true
label.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {
yAnchor.isActive = false
yAnchor = label.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: 200)
yAnchor.isActive = true
UIView.animate(withDuration: 1, delay: 1, usingSpringWithDamping: 0.5, initialSpringVelocity:5, options: .curveEaseIn, animations: {
self.view.layoutIfNeeded()
})
}
But I still do not know how to pause between the names. if I use a for .. loop to call this function it just runs them all at the same time?
Thanks