[英]How can I implement a pull down to dismiss a modal view in SwiftUI?
我正在顯示一個模態圖像選擇器,並且希望能夠在不單擊角落的取消按鈕的情況下關閉視圖(通過像 UIKit 一樣下拉)。
我的圖像選擇器與此一起顯示。
.sheet(isPresented: $isShowPhotoLibrary) {
ImagePicker(sourceType: .photoLibrary)
}
並像這樣實例化......
struct ImagePicker: UIViewControllerRepresentable {
var sourceType: UIImagePickerController.SourceType = .photoLibrary
func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> UIImagePickerController {
// Return an instance of UIImagePickerController
let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = false
imagePicker.sourceType = sourceType
return imagePicker
}
func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext<ImagePicker>) {
}
}
UIImagePickerController
覆蓋整個工作表的區域並且不允許處理拖動,因此,作為一種解決方法,一種可能的方法是添加某種凹口(概念是可識別的,因此可用性會很清楚)
這是一個演示(您可以根據您的應用程序設計構建樣式/背景)
VStack(spacing: 0) {
RoundedRectangle(cornerRadius: 2)
.frame(width: 60, height: 4).foregroundColor(.gray)
.padding(.vertical, 4)
ImagePicker(sourceType: .photoLibrary)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.