#ScrollViewReader
Explore tagged Tumblr posts
y2fear · 1 year ago
Photo
Tumblr media
ios - SwiftUI ScrollViewReader scrollTo doesn't scroll all the way to top
0 notes
arthurknopper · 4 years ago
Text
SwiftUI ScrollViewReader tutorial
In SwiftUI a ScrollViewReader is a view that provides programmatic scrolling inside sub views. With the scrollTo method the scrolling is executed. In his tutorial an item number can be chosen using a stepper. When the number is selected the ScrollViewReader will scroll to the chosen item. This tutorial is built for iOS 14 and Xcode 12, which can be download at the Apple developer portal.
Open Xcode and either click Create a new Xcode project in Xcode’s startup window, or choose File > New > Project. In the template selector, select iOS as the platform, select App template in the Application section and then click Next.
Tumblr media
Enter SwiftUIScrollViewReaderTutorial as the Product Name, select SwiftUI as Interface, SwiftUI App as Life Cycle and Swift as Language. Deselect the Include Tests checkbos and click Next. Choose a location to save the project on your Mac.
Tumblr media
In the canvas, click Resume to display the preview. If the canvas isn’t visible, select Editor > Editor and Canvas to show it.
Tumblr media
In the Project navigator, click to select ContentView.swift. Change the code inside the ContentView struct to
struct ContentView: View { // 1. let colors: [Color] = [.yellow, .red, .blue] @State private var itemNumber = 1 var body: some View { ScrollView { // 2. ScrollViewReader { value in HStack { // 3. Stepper(value: $itemNumber, label: { Text("Jump to Item: ") }) Button { withAnimation { // 4. value.scrollTo(itemNumber) } } label: { Text("\(itemNumber)") } }.padding() // 5. ForEach(1..<10) { i in Text("Item \(i)") .frame(width: 300, height: 200) .background(colors[i % colors.count]) .id(i) } } } } }
The property constant colors is use as background of the displayed items. The state variable will hold the current item number where will be scrolled to
The ScrollviewReader is used to provide access to the scrollTo method and the subview where will be scrolled to.
A stepper is displayed with the current value of the itemNumber which can be in- and decremented
The scrollTo(_:) method scrolls to the current view which matches the id of the view in the ForEach loop
The ForEach loop generates ten items with colored boxes, each item is assigned an id.
Go to the Preview and choose live preview. Change the number inside the stepper and click the number to scoll the selected colored item.
Tumblr media
The source code of the SwiftUIScrollViewReaderTutorial can be downloaded at the ioscreator repository on Github.
0 notes
ios-goodies · 5 years ago
Text
Week 342
Happy Thursday! Two weeks have passed since WWDC, so we got the second beta of Xcode 12 this week, as well as the second betas of the operating systems. What’s more, Apple is releasing the public beta of its operating systems today.
I’ve watched a few more WWDC videos these two weeks, and I’m impressed by all the work Apple did for privacy. I recommend watching Build trust through better privacy, What’s new in location and Handle the Limited Photos Library in your app. Or, if you prefer a written article to learn about the updates to accessing the photo library, you can check out Kuba’s Photo library changes in iOS 14.
Marius Constantinescu
Articles
The difference between @StateObject, @EnvironmentObject, and @ObservedObject in SwiftUI, by @mecid
Custom navigation bar title view in SwiftUI, by @sarunw
Refactoring iOS Apps, by @andreaslydemann
SwiftUI: Bridging UIKit with ScrollViewReader and DragGesture, by @zntfdr
Handling deeplinks in iOS 14 with onOpenURL, by @donnywals
A Best in Class iOS App, by @jordanmorgan10
MatchedGeometryEffect – Part 1 (Hero Animations), by @SwiftUILab
WWDC20: What’s New in Unit Testing, by @qcoding
Creating Lists with Collection View, by @kharrison
Tools/Controls
FNMNetworkMonitor - networking framework to monitor HTTP(s) activity of an iOS app, also it can mock network requests, by @diogobalseiro
Videos
WWDC 2020 Recap - Clips are Landing Pages, the Future of the Mac, and More, by @appfigures
Credits
mecid, sarunw, crsantos, andreaslydemann, zntfdr, rel, donnywals
0 notes
manzanitas · 5 years ago
Text
Favorite tweets
This is one of the animations we created today in the #SwiftUI Shape Series. I finished it off with a login screen. On a side note, I'm using ScrollViewReader to move text fields into view when tapped so they are above the keyboard. Project, Video: https://t.co/1YFxnmQnlw pic.twitter.com/x8zEbTJMm7
— Mark Moeykens (@BigMtnStudio) June 29, 2020
from http://twitter.com/BigMtnStudio via IFTTT
0 notes
manzanitas · 5 years ago
Text
A tweet
This is one of the animations we created today in the #SwiftUI Shape Series. I finished it off with a login screen. On a side note, I'm using ScrollViewReader to move text fields into view when tapped so they are above the keyboard. Project, Video: https://t.co/1YFxnmQnlw pic.twitter.com/x8zEbTJMm7
— Mark Moeykens (@BigMtnStudio) June 29, 2020
0 notes