Bird
0
0

Why does this SwiftUI layout code cause overlapping views?

medium📝 Debug Q7 of 15
iOS Swift - SwiftUI Layout
Why does this SwiftUI layout code cause overlapping views?
ZStack {
  Text("Top")
  Text("Bottom")
}
AZStack arranges views vertically by default
BZStack overlays views, so they appear on top of each other
CText views need explicit frames to avoid overlap
DZStack requires spacing parameter to separate views
Step-by-Step Solution
Solution:
  1. Step 1: Understand ZStack behavior

    ZStack overlays views in the same space, stacking them front to back.
  2. Step 2: Check if spacing applies

    ZStack does not use spacing; views overlap unless offset.
  3. Final Answer:

    ZStack overlays views, so they appear on top of each other -> Option B
  4. Quick Check:

    ZStack overlays = overlap [OK]
Quick Trick: ZStack stacks views overlapping each other [OK]
Common Mistakes:
  • Assuming ZStack arranges views vertically
  • Expecting spacing to separate ZStack views

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes