SwiftUI TabView covers content view
The contentView contains a List, and it fills all available space, moving buttons that are located below the List under the TabView. Adding Space after the contentView solves the issue.
var body: some View {
TabView {
VStack {
self.contentView
Spacer()
}
.tabItem {
Image(systemName: "chart.bar.fill")
Text("Chart")
}
Text("Screen 2")
.tabItem {
Image(systemName: "person.3.fill")
Text("Leaderboard")
}
Text("Screen 3")
.tabItem {
Image(systemName: "ellipsis")
Text("More")
}
}
}
Thank you @Asperi for pointing in right direction, and checking the children of the contentView.
Swift UI exporting content of canvas
This works fine!
The issue you are encountering is that in your sample code, canvasPallete
didn't get a frame modifier when snapshot()
was called on it. So it got rendered at a size that's not what you want, probably (0,0).
If you change the snapshot line it will work:
let image = canvasPallete
.frame(width: 300, height: 300)
.snapshot()
One more thing! In iOS 16, there's new API for rendering a view to an Image. So for iOS 16 and up, you can skip the View extension and write:
let renderer = ImageRenderer(content: canvasPallete)
if let image = renderer.uiImage {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
Dynamic content hight in VStack SwiftUI
ScrollView
Solved was putt all view in ZStack and add some fake views in Scroll view.
1 view is responsible for the size where the scroll cannot fall through.
2 view is responsible for the size between the maximum and minimum size of the header
Here's a examples
import Introspect
struct ContentView: View {
@StateObject private var myCoord = MyCoord()
var body: some View {
let sizeOfPlaceholder = myCoord.maxSize - myCoord.minSize
ZStack(alignment: .top) {
VStack(spacing: 0) {
Color.black
.frame(height: myCoord.minSize)
ScrollView {
Color.brown
.frame(height:sizeOfPlaceholder)
ForEach(0..<20) { number in
Text("\(number)")
.background(Color.red)
.frame(height: 20)
}
}
.padding(.vertical, 1)
.introspectScrollView { scroll in
scroll.delegate = myCoord
}
}
Color.green
.frame(height: myCoord.height)
}
}
}
class MyCoord: NSObject, UIScrollViewDelegate, ObservableObject {
let maxSize: CGFloat = 76
let minSize: CGFloat = 56
@Published var height: CGFloat = 76
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print(scrollView.contentOffset.y)
let size = maxSize - scrollView.contentOffset.y
height = min(maxSize, max(minSize, size))
}
}
dynamic content not updating in list Swift UI
struct ListItem: View {
var item: VocabItem
...
}
struct VocabList {
.
.
.
ForEach(items) { item in
ListItem(item: item)
}
}
Related Topics
Initialize Class-Instance and Access Variables in Swift
Swiftui iOS 14 Widget Countdown
Simple Swift Fibonacci Program Crashing (Project Euler 2)
How to Make Window Transparent in Osx Swift
Swift Firebase Must Be a Non-Empty String and Not Contain '.' '#' '$' '[' or ']'
Firebase: How to Update Multiple Nodes Transactionally? Swift 3
Firebase Get User Uid by Email
Distinction in Swift Between Uppercase "Self" and Lowercase "Self"
Closure Use of Non-Escaping Parameter May Allow It to Escape
Swift: Orient Y-Axis Toward Another Point in 3-D Space
How Does One Trap Arithmetic Overflow Errors in Swift
Arkit - How to Export Obj from Iphone/iPad with Lidar
Property Observers Willset and Didset; Property Getters and Setters
Swift - Increment Label With Stepper in Tableview Cell
How to Use Generic Types to Get Object with Same Type