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

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

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

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

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


当前回答

你可以试试我的答案https://github.com/SCENEE/FloatingPanel。它提供了一个容器视图控制器来显示“底层表”接口。

它很容易使用,你不介意任何手势识别器处理!如果需要,还可以在底部表单中跟踪滚动视图(或兄弟视图)。

这是一个简单的例子。请注意,你需要准备一个视图控制器来在底部表单中显示你的内容。

import UIKit
import FloatingPanel

class ViewController: UIViewController {
    var fpc: FloatingPanelController!

    override func viewDidLoad() {
        super.viewDidLoad()

        fpc = FloatingPanelController()

        // Add "bottom sheet" in self.view.
        fpc.add(toParent: self)

        // Add a view controller to display your contents in "bottom sheet".
        let contentVC = ContentViewController()
        fpc.set(contentViewController: contentVC)

        // Track a scroll view in "bottom sheet" content if needed.
        fpc.track(scrollView: contentVC.tableView)    
    }
    ...
}

下面是另一个示例代码,用于显示底部表单以搜索Apple Maps之类的位置。

其他回答

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扩展。

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

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

你可以试试我的答案https://github.com/SCENEE/FloatingPanel。它提供了一个容器视图控制器来显示“底层表”接口。

它很容易使用,你不介意任何手势识别器处理!如果需要,还可以在底部表单中跟踪滚动视图(或兄弟视图)。

这是一个简单的例子。请注意,你需要准备一个视图控制器来在底部表单中显示你的内容。

import UIKit
import FloatingPanel

class ViewController: UIViewController {
    var fpc: FloatingPanelController!

    override func viewDidLoad() {
        super.viewDidLoad()

        fpc = FloatingPanelController()

        // Add "bottom sheet" in self.view.
        fpc.add(toParent: self)

        // Add a view controller to display your contents in "bottom sheet".
        let contentVC = ContentViewController()
        fpc.set(contentViewController: contentVC)

        // Track a scroll view in "bottom sheet" content if needed.
        fpc.track(scrollView: contentVC.tableView)    
    }
    ...
}

下面是另一个示例代码,用于显示底部表单以搜索Apple Maps之类的位置。

我写了自己的库来实现ios地图应用程序的预期行为。这是一个面向协议的解决方案。因此,您不需要继承任何基类,而是创建一个表控制器,并按照您的意愿进行配置。它还支持内部导航/表示,有或没有UINavigationController。

更多细节请参见下面的链接。

https://github.com/OfTheWolf/UBottomSheet

我们刚刚发布了一个支持iOS 11.4+的纯Swift包,它为您提供了一个底部表,其中包含您可以自定义的主题和行为选项。该组件使用方便,灵活。你可以在这里找到它:https://github.com/LunabeeStudio/LBBottomSheet。 在这个存储库中还提供了一个演示项目。

例如,它支持不同的方式来管理所需的高度,还添加到它后面的控制器的能力,以检测高度变化和适应其底部内容嵌入。

你可以在GitHub存储库和文档中找到更多信息:https://lbbottomsheet.lunabee.studio。

我觉得它能帮你做你想做的事。如果你有意见或问题,请不要犹豫,告诉我:)

在这里你可以看到所有可能的BottomSheet配置之一: