有人能告诉我如何在iOS 10的新苹果地图应用程序中模仿底部表格吗?

在Android中,你可以使用一个BottomSheet来模仿这种行为,但我在iOS中找不到任何类似的东西。

这是一个简单的带有内容嵌入的滚动视图,以便搜索栏在底部吗?

我对iOS编程相当陌生,所以如果有人能帮助我创建这个布局,那将是非常感谢的。

这就是我所说的“底稿”:


当前回答

也许你可以试试我的答案https://github.com/AnYuan/AYPannel,灵感来自滑轮。从移动抽屉到滚动列表的平稳过渡。我在容器滚动视图中添加了一个平移手势,并设置shouldRecognizeSimultaneouslyWithGestureRecognizer返回YES。更多细节在我的github链接上面。希望能帮上忙。

其他回答

**为iOS 15本机支持提供此**

@IBAction func openSheet() { 
        let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController")
        // Create the view controller.
        if #available(iOS 15.0, *) {
            let formNC = UINavigationController(rootViewController: secondVC!)
            formNC.modalPresentationStyle = UIModalPresentationStyle.pageSheet
            guard let sheetPresentationController = formNC.presentationController as? UISheetPresentationController else {
                return
            }
            sheetPresentationController.detents = [.medium(), .large()]
            sheetPresentationController.prefersGrabberVisible = true
            present(formNC, animated: true, completion: nil)
        } else {
            // Fallback on earlier versions
        }
   }

如果你正在寻找一个使用视图结构的SwiftUI 2.0解决方案,这里是:

https://github.com/kenfai/KavSoft-Tutorials-iOS/tree/main/MapsBottomSheet

iOS 15终于添加了一个本地UISheetPresentationController!

官方文档 https://developer.apple.com/documentation/uikit/uisheetpresentationcontroller

也许你可以试试我的答案https://github.com/AnYuan/AYPannel,灵感来自滑轮。从移动抽屉到滚动列表的平稳过渡。我在容器滚动视图中添加了一个平移手势,并设置shouldRecognizeSimultaneouslyWithGestureRecognizer返回YES。更多细节在我的github链接上面。希望能帮上忙。

2021年的iOS 15添加了UISheetPresentationController,这是苹果首次公开发布苹果地图风格的“底稿”:

UISheetPresentationController UISheetPresentationController lets you present your view controller as a sheet. Before you present your view controller, configure its sheet presentation controller with the behavior and appearance you want for your sheet. Sheet presentation controllers specify a sheet's size based on a detent, a height where a sheet naturally rests. Detents allow a sheet to resize from one edge of its fully expanded frame while the other three edges remain fixed. You specify the detents that a sheet supports using detents, and monitor its most recently selected detent using selectedDetentIdentifier. https://developer.apple.com/documentation/uikit/uisheetpresentationcontroller

在WWDC Session 10063:在UIKit中自定义和调整表大小中探索了这个新的底部表控件


不幸的是……

在iOS 15中,UISheetPresentationController已经启动,只有中型和大型止动。

值得注意的是,iOS 15 API中没有一个小的缺陷,它将被要求显示像Apple Maps那样始终呈现的“折叠”底部表:

在UISheetPresentationController中自定义更小的止损?

释放了介质止动,以处理共享表或邮件中的“•••More”菜单等用例:按钮触发的半页。

在iOS 15中,苹果地图现在使用这种UIKit表格表示,而不是自定义实现,这是朝着正确方向迈出的一大步。iOS 15中的苹果地图继续显示“小”条,以及1/3高的条。但是这些视图大小并不是开发人员可用的公共API。

WWDC 2021实验室的UIKit工程师似乎知道,一个小的detent将是一个非常受欢迎的UIKit组件。我希望明年能看到iOS 16的API扩展。