SwiftUI_visionOS_Note
Anything I learnt today about building visionOS app
-
.onLongPressGesture
-
MagnificationGesture
-
Map
While most iOS tutorials are engaging, they often don't function well on visionOS. I spend the most of time modifying them to work, either intentionally or unintentionally.
-
ToDo List
-
NavigationStack
NavigationLink , It only move up and back on stack only When it’s under NavigationStack, it can moves up and down freely. Text will show screen # and when the view is initialized, it will print the which screen # got called This is a Swift code snippet for a SwiftUI application. It creates a split view navigation interface. The primary view contains a scrollable VStack with 10 navigation links, each leading to 'MySecondScreen' and passing a different value from 0 to 9.
-
.onSubmit
As of iOS 15, we can use the new .submitLabel modifier to change the color and text of the submit button on the keyboard. Even more importantly, we can also use .onSubmit to run custom functions when users click on the submit button! These features were not available before iOS 15 in SwiftUI.
-
@FocusState
In practice, this will most often be associated with users clicking on TextFields. In this video, we will first learn what Focus State is and then review a few real-world implementations! As a bonus, we will also check out Apple's documentation on this new feature.
-
.badge
-
.swipeActions()
Previously, we List rows were limited to only 1 swipe action - swipe to delete. Now, however, we can totally customize these rows and add a whole bunch of buttons to them. We will implement a few different variations of list row actions, each with different colors, titles, and swiping from both the leading and the trailing edge.
-
System Material
These System Materials are very commonly used as backgrounds for a subtle, yet professional look to your apps. As you'll see, the colors are not totally opaque and allow some natural color to bleed through.
-
AsyncImage
Asynchronously download image from URL When the view appear, AsyncImage will read the data and put it inside the container. It will fetch the data every time we run the view. Image is bigger than the frame size, so other outside part will be cut off. Now returnedImage can use the modifier properly just like Image()
-
.buttonStyle & .controlSize
For the button Style, which one should I use? .buttonStyle(BorderlessButtonStyle()) or .buttonStyle(.borderless)
-
TextSelection()
This is great for chat apps or any content-based app where users might want to share some text with a friend. Sharing is not only a great feature for your users, but will help drive organic growth as users share with others.
-
@EnvironmentObject
The @EnvironmentObject is a super-useful property wrapper that lets us put an observable object into the environment of our SwiftUI application. By doing this, all of these views in the view hierarchy will then have access to this object. This is the perfect solution for any case where you have a class that needs to be accessed by multiple views, but you don't want to manually bind it from view to view to view with initializers.
-
@AppStorage
We can save the small piece of data when the app is closed. Once we close the app on HomeView, we will never see the OnboardingView again. Important: @AppStorage writes your data to UserDefaults, which is not secure storage. As a result, you should not save any personal data using @AppStorage, because it’s relatively easy to extract.
-
@StateObject & @ObservableObject
Now fruit model has string id, name and count inside the Hstatck text will bring the data from the fruitArray Why is important? → @StateObject → INIT → @ObservedObejct → Subview Today, I learned about ObservableObject and StateObject. These are property
-
Custom model
Custom data types are frequently needed in our applications. They allow us to incorporate multiple data points into a single model. For instance, a User's data may need to encompass more than just their name. By creating a custom data type, we can encompass their name, username, email, bio, and more, all within a single object.
-
Tap gesture
The .onTapGesture modifier functions much like a button and can even be customized to recognize multiple taps instead of just one (double-tap, triple-tap, etc.). count: number of taps to perform the action just like instagram.
-
onAppear & onDisappear
#modifier The onAppear and onDisappear modifiers are extremely convenient methods that let us call functions when specific components appear or disappear from the screen. These are often used for managing animations and loading data in SwiftUI applications.
-
SAFE CODING: if let & guard
In Swift, variables can be declared as optional using the '?' symbol, indicating they may be nil. To safely check and unwrap these optional variables, 'if let' and 'guard' statements are recommended. These methods are safer than explicitly unwrapping optionals using the '!' symbol, which should be avoided.
-
toolbar
-
Adapting Dark Mode in visionOS??
VisionOS’s default colour scheme is “Default” We can change how it seems under preview by adding .preferredColorScheme(.light) or we can use the adaptive colour in assets or we can create an enviroment variable to make it locally adaptive @Environment(\.colorScheme) var colorScheme
-
add: Markups & Documentation
by writing // MARK: TITLE, it leaves a flag on minimap. and we can comment it like this and we can fold it by pressing option+command+arrow we can simplify the code by extracting subviews from the body We can comment what this code is for Use documentation to write a clear guideline and instructions for other people to understand
-
TabView()
-
Slider
Choose slider with value completion binaryPoint is just number, we will bind double 10 to a value by using .tint() .Slider(value: $sliderValue, in: 0...20) .Slider(value: $sliderValue, in: 0...20, step: 1.0) instead of showing 0.0000001 value, we can format the number to show how many decimal points we want to show. .Text(String(format: "%.2f", sliderValue)
-
Stepper
what is Strideable? A type representing continuous, one-dimensional values that can be offset and measured. You can use a type that conforms to the Strideable protocol with the stride(from:to:by:) and stride(from:through:by:)functions. For example, you can use stride(from:to:by:) to iterate over an interval of floating-point values:
-
ColorPicker()
-
DatePicker()
The DatePicker is a native SwiftUI component for selecting date and/or time. You can implement it using various initializers and customize it with different DatePickerStyles. Additionally, a DateFormatter can be used to effectively display dates in your visionOS application.
-
Picker()
-
toggle()
-
TextEditor()
-
TextField()
-
.contextMenu()
#swiftui #visionos #applevisionpro #visionpro
-
function
Let’s say we want to print this lines of string on the screen. It’s okay to use if this is on only one screen. But what if it’s on multiple pages? () are used with functions. When we create a function, () are used. or, When we call the function: ask swift to run the code
-
.actionSheet()
.actionSheet() is not supported in VisionOS. Use .confirmationDialog() instead. In a popup screen, it's possible to list more than two buttons to modify the view. Vision Pro can be preordered starting from January 19 at 5AM PST. #visionOS #applevisionpro #visionpro #spatialcomputing
-
Alert
-
Loop, While & Skip
We can repeat and fix in array, dictionary, or set Heres an array of string, and print each string like following code We call the value of os from platforms. it will print 4 lines of text we can loop over the fixed amount of number 1...12 is "range" we can put loops inside the loops, "nested loops"
-
How to use List()
#toolbar Apple developer (List of Style) #visionOS #applevisionpro #swiftUI #appdevelopment This video provides the opportunity to experience a spatial video on my Quest 2. The immersion was remarkable, similar to viewing a 3D movie up close with 3D glasses. However, I noticed that the performance fell short when it came to distant fixtures, scenes, or panoramic views. #VR #SpatialVideo #Quest2
-
NavigationStack & NavigationLink
-
.sheet() vs .transition() vs .animation
Previous .transition() note, we only used a single button to toggle the screen. This time we will use @Binding and other button on the new screen to toggle. For your information, it appears really impressive.
-
.sheet() & .fullScreenCover()
We didn’t assign anything on that “X” button, so we can’t go back to the screen. Someone told me, "you should learn AI instead of VisionOS." However, I'm interested in building experiences, which is why I'm focusing on MR.
-
Transition
// .transition(.scale) // .transition(.slide) // .transition(.move(edge: .top)) // .transition(.opacity) Use .transition to animate an object's entry and exit.
-
Adding Animation
In SwiftUI, animations can be added using withAnimation(). A button and a rounded rectangle can be created, with a boolean variable isAnimated used to change the value of elements. The withAnimation() function provides animation features in the view, and can be used to change the offset value and give rotation effects for dynamic animations. Delayed or repeating animations can be added using .delay(double) or .repeatCount(). Note that .animation() is not allowed in visionOS, use withAnimation(Animation.default) instead.
-
Animation curves & timing
In most cases, we use Animation.default. However, it's enjoyable to experiment with different types of animations. 👿 How can I animate all six squares using a single button? #visionOS #applevisionpro #swiftUI #studying
-
N - Voice Record