Challenge - 5 Problems
ScrollView Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
ScrollView Content Size Behavior
What will happen if you place a VStack with fixed height inside a ScrollView without setting the ScrollView frame height?
iOS Swift
ScrollView {
VStack {
Rectangle().frame(height: 1000)
}
}Attempts:
2 left
💡 Hint
Think about how ScrollView calculates its content size based on child views.
✗ Incorrect
ScrollView automatically sizes its content area to fit the child views. Since the VStack has a fixed height of 1000, the ScrollView will allow vertical scrolling to show all content.
❓ lifecycle
intermediate2:00remaining
ScrollView and State Updates
If you update a @State variable inside a ScrollView's content, what happens to the ScrollView's position?
iOS Swift
struct ContentView: View {
@State private var count = 0
var body: some View {
ScrollView {
VStack {
Text("Count: \(count)")
Button("Increment") { count += 1 }
}
}
}
}Attempts:
2 left
💡 Hint
Think about how SwiftUI preserves scroll position on state updates.
✗ Incorrect
SwiftUI preserves the scroll position when the view updates due to state changes inside ScrollView content. The ScrollView does not reset or jump automatically.
advanced
2:00remaining
Programmatic ScrollView Scrolling
Which code snippet correctly scrolls a ScrollView to the bottom when a button is tapped?
Attempts:
2 left
💡 Hint
Remember to use ScrollViewReader and assign IDs to scroll targets.
✗ Incorrect
Option A correctly uses ScrollViewReader to get a proxy, assigns IDs to views, and calls scrollTo with the correct ID. Other options either lack ScrollViewReader or place the button inside ScrollView incorrectly.
📝 Syntax
advanced2:00remaining
Correct ScrollView Axis Syntax
Which code snippet correctly creates a horizontal ScrollView in SwiftUI?
Attempts:
2 left
💡 Hint
Check the official ScrollView initializer parameters.
✗ Incorrect
Option D uses the correct initializer with axis parameter as .horizontal and a matching HStack inside. Option D and C use wrong parameter names. Option D uses VStack inside horizontal ScrollView, which is allowed but less common and may cause layout issues.
🔧 Debug
expert2:00remaining
ScrollView Content Not Scrolling
Why does this ScrollView not scroll even though the content is larger than the screen?
iOS Swift
ScrollView {
VStack {
ForEach(0..<20) { i in
Text("Item \(i)").frame(height: 50)
}
}
}.frame(height: 200)Attempts:
2 left
💡 Hint
Check the total height of VStack content compared to ScrollView frame height.
✗ Incorrect
Each Text has height 50, 20 items total 1000 height. But the VStack inside ScrollView does not expand beyond the ScrollView frame height of 200 because ScrollView limits its child size. So content size is not larger than frame, no scrolling.