The presentationDetents(_:)
modifier in SwiftUI is used to add a pull down "detent" to a modal view, allowing the user to partially dismiss the sheet. This modifier does not directly control the height of the sheet.
Instead, you can use the frame(maxHeight:)
modifier to set a maximum height for the sheet. For example:
.sheet(isPresented: $isSheetPresented) {
MySheetView()
.frame(maxHeight: 500)
.presentationDetents([.medium()])
}
In this example, the maximum height of the sheet is set to 500 points. When the detent is used to partially dismiss the sheet, the maximum height will remain the same.
If you want the sheet to dynamically adjust its height based on the contents, you can use a combination of GeometryReader
and frame(minHeight:idealHeight:maxHeight:)
. For example:
.sheet(isPresented: $isSheetPresented) {
GeometryReader { geometry in
MySheetView()
.frame(minHeight: 0, idealHeight: geometry.size.height, maxHeight: geometry.size.height)
.presentationDetents([.medium()])
}
}
In this example, the GeometryReader
allows us to get the size of the container and use it to set the frame
of the sheet. The minHeight
is set to 0 to allow for dynamic resizing, idealHeight
is set to the height of the container, and maxHeight
is set to the same as idealHeight
to prevent the sheet from resizing when the detent is used.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-04-08 11:00:00 +0000
Seen: 11 times
Last updated: Mar 10 '23
How can the update of properties from both ParentViewModel and ChildViewModel in SwiftUI be solved?
How can I deal with Expression.Error related to a column in Power Query?
How can you implement pagination in Oracle for the LISTAGG() function?
What is the process for implementing a FutureBuilder on an OnTap function in Flutter?
How can we require users to be logged in before they can access the root folders in WordPress?
In SCSS, what is the method for grouping and reusing a set of classes and styles?
How can popen() be used to direct streaming data to TAR?
How does iOS retrieve information from a BLE device?
How can Django Admin accommodate a variety of formats and locales for its input fields?