I have the following animation and I can't seem to figure out why it is not working consistently. The stack view is a series of UILabel subviews where I want to animate: hiding all of the labels without text and showing all that do. I have tried using UIView.beginAnimations("Animation", nil)
and UIView.commit()
around the whole thing (when I had it structured as multiple animation blocks). I have tried having them in separate blocks, but I can't seem to figure out why it's not working.
When printing out inside the animation block it shows:
<UILabel: 0x7fa237408b90; frame = (0 0; 195 130); text = '1'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000004645a0>>
<UILabel: 0x7fa2374088a0; frame = (195 65; 0 0); text = '0'; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600000464460>>
hide <UILabel: 0x7fa2374085b0; frame = (195 65; 0 0); text = ''; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600000464190>>
hide <UILabel: 0x7fa2374082c0; frame = (195 65; 0 0); text = ''; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600000464050>>
hide <UILabel: 0x7fa237407e50; frame = (195 65; 0 0); text = ''; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600000459270>>
hide <UILabel: 0x7fa237407b60; frame = (195 65; 0 0); text = ''; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60000045a990>>
I have also tried making this on the main thread both inside the animation block and outside. Inside the block it cancels out the animation and outside the block it makes no difference. Also if you comment out the view.isHidden = false
the part that makes view not hidden appears to work as expected.
UIView.animate(withDuration: 0.2){[unowned self] in
self.stackView.arrangedSubviews.forEach{(view) in
if((view as! UILabel).text == ""){
print("hide \(view)")
view.isHidden = true
}else{
print(view)
view.isHidden = false
}
}
}//End of animation
Any help is greatly appreciated.