Peek-a-boo

Choosing the right way to hide a view was short & sweet. Essentially, there are two objectives when hiding a view. Hide and save the space, or hide and pretend like it was never there. We can use .opacity(_:) and VoiceOver will respect that we don’t want a zero-opacity view to be ‘voiced’, yet the space will remain. If we want to close the space, we can use a Conditional (if) statement.

Apple uses a train example, I’m using shapes.
We use a boolean @State var to control both Conditional & Opacity lines.

// Conditional
if moreShapes {
    Image(systemName: "triangle"
}

// Opacity
Image(systemName: "triangle")
    .opacity(moreShapes ? 0 : 1)

to recap, if we want to hide a view, and pretend like it was never there, use a Conditional approach

if we want to save the space, use Opacity

Standard

Leave a comment