I'm stumble on two problems. I'm trying to cnstruct a view which will contain elements placed on full display of the watch (from top to bottom, full-screen). Some watch apps has such views.
Code below shows how to move content to the top+left edge of the display. And there are two problems.
var body: some View {
ZStack(alignment: .topTrailing) {
Rectangle().foregroundColor(Color.green)
HStack(spacing: 0) {
VStack(alignment: .trailing, spacing: 0) {
Text("Hello World")
.padding(.trailing, 20)
Text("Hello World")
Text("Hello World")
}
}
}.edgesIgnoringSafeArea(.all)
.navigationBarHidden(true)
}
As you can see, element Text aligned to the top+trailing with little padding.
By default on the top of display Navigation Bar with Timer are displayed. Modificator '.navigationBarHidden(true)' working and properly hides Navigation Bar, but not a Timer. This is the first problem.
I can't post the image yet.
Second problem: Two warnings are displaying in console while running the app on simulator. And i'm not sure of its meanings. Despite of the warnings simulator is is not crushed.
WatchKit Extension libMobileGestalt utility.c:421: no value found for key 1129072723
WatchKit Extension [default] has no material, defaulting to light aluminum.
My appretiations in advance.
For your first problem, you cannot remove the time from the navigation bar. The primary focus for the AW is to tell time, therefore it should always be visible. The only occasions when the time is not visible is when dictating or writing something using the swipe 'keyboard'.
Warnings are not necessarily a problem, you can ignore these (especially the second one)
Related
What I am trying to build
Apple Watch app(written in SwiftUI, targeting watchOS 7 or higher, built with Xcode 14.1)
The Problem
Picker placed inside a ScrollView on an apple watch device does not work as expected
I want to find out how to get the Picker to work as expected, stated below.
Expected behavior
On an iOS simulator, a Picker inside a ScrollView works as expected.
If I try scroll interaction on the Picker area, the ScrollView part doesn’t get scrolled and only the Picker gets scrolled.
whereas on the watch simulator Example,
If I try to scroll the Picker by touching the Picker area, the whole ScrollView reacts and moves up and down. And I am not able to control the Picker properly.
The code I wrote is as follows:
ScrollView {
//..other view elements..
Picker(selection: $currentDay) {
ForEach(weekDays, id: \.self) {
Text($0)
}
} label: {
Text("")
}
.frame(width: 148,height: 50)
.pickerStyle(.wheel)
//..other view elements..
}//: ScrollView
Things I have tried
putting the Picker inside a VStack/ZStack/HStack
giving the Picker fixed frame values / giving other elements inside the ScrollView fixed frame values
Is there a good way to hide the up down arrows in the picker default style. I am using ios 16. It seems that the older version does not have such arrows.
Also, is there a setting to set the picker's background to the same style as the datepicker in the image without manually setting the background and radious?
I have been struggling on this small feature and tried googling for a few hours but no luck. Any idea will be appreciated
The suggested Menu solution works well if you only have a few options. The problem I've experienced with the Menu solution is that if there are very many options the Menu doesn't automatically scroll to the currently selected option the way the Picker does.
The solution I've used is to use ZStack to place an opaque picker on top of a custom view (my "label"). Setting the opacity modifier on the Picker to 0.025 makes it invisible on your device but it will still trigger when you tap it.
This way you get all the native functionality of the Picker (including scrolling to the selected option) and you can make the label look any way you want without having to create your own custom picker.
Here's the code:
ZStack {
// Custom picker label
Text("\(value)")
.font(.title)
.foregroundColor(.blue)
.styleDataEntry(colorScheme: colorScheme) // a custom formatter View extension
// Invisible picker
Picker("", selection: $value) {
ForEach(0 ..< 200) { option in
Text("\(option)").tag(option)
}
}
.pickerStyle(.menu)
.opacity(0.025)
}
There are two solutions I have seen can be used to change the colour of the title bar in SwiftUI:
Making the use of NavigationView
Ignoring the sage area with .ignoresSafeArea()
I have no use for a NavigationView nor I want to use .ignoresSafeArea() since it helps on giving the TabView bottom tab space.
The only requirement to the solution I am looking for is that it cannot be for iOS 16 and above only, since it will not be viable to use in production for at least the next two years.
TL;DR:
I need to change the colour of the title bar (the upper-most part of the app) with features available in versions prior to iOS 16, and without the use of NavigationView and .ignoresSafeArea()
The white stuff in this image:
I am using TabView in my SwiftUI app. I used the side Preview as I was building it. The bottom tab shows on all device types in the Preview section but when I build it to either a real device or simulate device, the TabView doesn't show at all.
Previews are for each individual view. They don't represent the whole app.
You'll need to set it as the root view inside YourAppName_App.swift.
#main
struct YourAppNameApp: App {
var body: some Scene {
WindowGroup {
YourTabBarView() /// replace with the name of your tab bar view
}
}
}
After adding a combined gesture to a view, a TextField inside the view would no longer respond when I would tap into it to change the text. I discovered this after adding a custom combined gesture - where I used a long press to start things before dragging. (Note: things still worked if just a drag gesture was added. Not sure what is particularly different between these two cases.)
The combined gesture:
let combined = longPressGesture.simultaneously(with: dragGesture)
The gesture was added to the view with:
.gesture(combined)
I got things to work by adding an onTapGesture{} to the TextField. Didn’t have to put anything into the action. Seems like a side effect whose behavior could change in the future. Appreciate any comments on if this makes sense or other ways to handle.
TextField(“Enter Text”, text: $myText)
.textFieldStyle(RoundedBorderTextFieldStyle())
.onTapGesture {}
In case one would have this issue with a drag gesture, you can set the minimumDistance. This would still register the tap on the textfield to edit it.
DragGesture(minimumDistance: 30, coordinateSpace: .global)
Adding a drag gesture in SwiftUI to a View inside a ScrollView blocks the scrolling