Bird
0
0

How can you make a ScrollView that scrolls vertically but also allows horizontal scrolling for wide content inside it?

hard📝 Application Q9 of 15
iOS Swift - SwiftUI Layout
How can you make a ScrollView that scrolls vertically but also allows horizontal scrolling for wide content inside it?
AUse a single vertical ScrollView with HStack inside
BNest a horizontal ScrollView inside a vertical ScrollView
CUse only a horizontal ScrollView with VStack inside
DUse a ZStack with fixed frames
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested scrolling

    Nesting a horizontal ScrollView inside a vertical ScrollView allows independent scrolling in both directions.
  2. Step 2: Evaluate other options

    Single vertical ScrollView with HStack clips horizontal content; horizontal ScrollView alone won't scroll vertically; ZStack overlays views without scrolling.
  3. Final Answer:

    Nesting horizontal ScrollView inside vertical ScrollView enables both scroll directions -> Option B
  4. Quick Check:

    Nested ScrollViews for 2D scroll = Nest a horizontal ScrollView inside a vertical ScrollView [OK]
Quick Trick: Nest horizontal ScrollView inside vertical ScrollView for 2D scroll [OK]
Common Mistakes:
  • Expecting single ScrollView to scroll both ways
  • Using only HStack inside vertical ScrollView
  • Using ZStack for scrolling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes