片材下方的插入内容带有中等制动装置
iOS 15 添加了 UISheetPresentationController
,它允许您通过将 sheetPresentationController
的制动器设置为 [.medium()]
来实现半高工作表。然后,您可以将 LargestUndimmedDetentIdentifier 设置为 .medium,以允许与呈现的视图控制器和工作表进行交互,从而实现类似于地图和股票的界面。
我的问题是,如何检测何时呈现未变暗的工作表并获取其高度以便在底层屏幕中插入内容。例如,我想将内容插入添加到我的表格视图中,以便您可以滚动查看所有单元格。目前,工作表覆盖了底部单元格,使其无法与这些单元格交互 - 您只能点击工作表所在位置上方的单元格。
iOS 15 added UISheetPresentationController
which allows you to implement a half-height sheet by setting sheetPresentationController
's detents to [.medium()]
. You can then set the largestUndimmedDetentIdentifier
to .medium
to allow interacting with the presenting view controller and the sheet so you can achieve an interface similar to Maps and Stocks.
My question is, how could you detect when an undimmed sheet is presented and get its height in order to inset content in the underlying screen(s). For example, I want to add content insets to my table view so that you can scroll to see all cells. Currently, the sheet covers up the bottom cells making it impossible to interact with those - you can only tap the ones that lie above where the sheet rests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,请设置
sheetPresentationController.delegate
并采用UISheetPresentationControllerDelegate
协议。这将通知您何时出现和何时消失。然后,您可以在animateChanges
块中根据需要对内容进行动画移动。这是一个示例:请注意,中等制动高度看似不确定,但接近屏幕高度的一半。如果您需要精确调整界面,iOS 16 添加了提供自定义制动器的功能,您可以在其中指定所需的确切高度。这是一个例子:
To do this, set the
sheetPresentationController.delegate
and adopt theUISheetPresentationControllerDelegate
protocol. This will inform you when it will present and did dismiss. You can then animate moving your content as appropriate in ananimateChanges
block. Here's an example:Note the medium detent height is seemingly indeterminate but close to half the screen height. If you need to precisely adjust your interface, iOS 16 adds the ability to provide a custom detent where you specify the exact height desired. Here's an example: