![]() You can take full control of the appearance of your app by modifying the source code. On top of that, the app template includes the full Xcode source files. Simply pick the one you love, build the project and you'll achieve a different app UI. ![]() To use that capability, let’s start by creating a PositionObservingView, which lets us bind a CGPoint value to the current position of that view relative to a CoordinateSpace that we’ll also pass in as an argument. The template includes multiple storyboards for you to choose from. While GeometryReader is mostly used to access the size of the view that it’s hosted in (or, more accurately, that view’s proposed size), it also has another neat trick up its sleeve - in that it can be asked to read the frame of the current view relative to a given coordinate system. That’s where our good old friend GeometryReader comes in (wouldn’t be a proper SwiftUI layout workaround without it, right?). So if we can find a way to observe the frame of that container, then we’ll essentially have found a way to observe the scroll view’s content offset. They then clip that container to their bounds to produce the illusion of the viewport moving. One thing that’s key to realize before we begin is that both UIScrollView and SwiftUI’s ScrollView perform their scrolling by offsetting a container that’s hosting our actual scrollable content. So, let’s instead see if we can find a completely SwiftUI-native way to perform such content offset observations. So in this iPhone app tutorial, you’ll get hands-on experience doing exactly that by making a simple RSS reader app This iPhone app tutorial was specially requested and sponsored by William Mottl, a kind supporter of this blog. Not impossibly by any means, but still, a fair bit of additional work and complexity. That’s a lot of different concepts to put together. So if we wanted to build a custom, observable version of ScrollView using UIScrollView, then we’d have to wrap that implementation in a view controller, and then manage the relationship between our UIHostingController and things like the keyboard, the scroll view’s content size, safe area insets, and so on. That’s mainly because - at least on iOS - we can only embed SwiftUI content within a UIHostingController, not within a self-managed UIView. However, even though I’m normally a big fan of using UIViewRepresentable and the other SwiftUI/UIKit interoperability mechanisms, in this case, we’d have to write quite a bit of extra code to bridge the gap between the two frameworks. One way to solve that problem would be to utilize the rich capabilities of UIKit’s UIScrollView, which - thanks to its delegate protocol and the scrollViewDidScroll method - provides an easy way to get notified whenever any kind of scrolling occurred. While embedding a ScrollViewReader within a scroll view does enable us to change the scroll position in code, it strangely (especially given its name) doesn’t let us read the current content offset in any way. Go to the File > New > File menu in Xcode. However, when it comes to SwiftUI’s ScrollView, there’s currently (at the time of writing) no built-in way to perform such scrolling observations. It works, but if you want a fully-functional Mac RSS reader, you should check out the excellent and free NetNewsWire.When building various kinds of scrollable UIs, it’s very common to want to observe the current scroll position (or content offset, as UIScrollView calls it) in order to trigger layout changes, load additional data when needed, or to perform other kinds of actions depending on what content that the user is currently viewing. RssBucket is very much a sample application. Changing the import name or behaviour would be also. And updating occurs on a different thread from the UI. This is kept as the import name to be consistent with different kind of tutorials around the internet. When you shut the application down, it saves off the feed list in your Preferences using NSUserDefaults. Below the list is a web view that opens the URL for the selected entry. To the right is a list of the selected feed’s entries, with a more human-readable date and a link arrow to open the entry in the default web browser. It has a standard source list, with feeds, favicons, and counts. My previous Cocoa tutorials about link arrows, badges, and dates were extracted from the application. I’m making the source code available as well (for Xcode/IB 3.1), under the MIT license, so feel free to use it wherever. Of course, then I thought it would be fun to release that reader to the public. ![]() To familiarize myself with the language and framework, I wrote an RSS reader, and I had planned to throw that code away as soon as I felt comfortable building a real application. I started programming in Objective-C and Cocoa in April.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |