将关闭按钮添加到底部工作表
在 Apple 关于工作表视图的文档中,他们演示了如何实例化一个视图控制器,该视图控制器显示底部工作表,右侧有一个“关闭”按钮。考虑下面的照片:
我很难复制这一点。当我在导航控制器中呈现工作表视图并显式添加关闭按钮时,我可以看到关闭按钮,但工作表变成了 .large() 制动器。他们的照片表明他们正在通过 .medium() 制动装置实现这一目标。 UISheetPresentationController 的文档没有显示其他替代方案。知道我做错了什么吗?
我的 SheetController:
override func viewDidLoad() {
....
navigationItem.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .done, target: self, action: #selector(closeSheet))
....
}
在不同的控制器中,单击按钮即可启动sheetController 的呈现:
@objc func showTheSheet() {
let updateController = MySheetController()
if let sheet = updateController.sheetPresentationController {
sheet.detents = [.medium()]
sheet.largestUndimmedDetentIdentifier = nil
sheet.prefersGrabberVisible = true
sheet.prefersScrollingExpandsWhenScrolledToEdge = true
sheet.prefersEdgeAttachedInCompactHeight = true
sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true
}
let navController = UINavigationController(rootViewController: updateController)
self.present(navController, animated: true, completion: nil)
}
In Apple's documentation on Sheet Views, they demonstrate how to instantiate a view controller that displays a Bottom Sheet with a "close" button on the right-hand side. Consider the photo below:
I am having a hard time replicating this. When I present the Sheet View in a NavigationController, and explicitly add a close button, I can see the close button but the sheet becomes a .large() detent. Their photo suggests they are achieving this with a .medium() detent. Documentation for UISheetPresentationController shows no other alternative. Any idea what I am doing wrong?
My SheetController:
override func viewDidLoad() {
....
navigationItem.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .done, target: self, action: #selector(closeSheet))
....
}
In a different controller, a button click initiates the presentation of the sheetController:
@objc func showTheSheet() {
let updateController = MySheetController()
if let sheet = updateController.sheetPresentationController {
sheet.detents = [.medium()]
sheet.largestUndimmedDetentIdentifier = nil
sheet.prefersGrabberVisible = true
sheet.prefersScrollingExpandsWhenScrolledToEdge = true
sheet.prefersEdgeAttachedInCompactHeight = true
sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true
}
let navController = UINavigationController(rootViewController: updateController)
self.present(navController, animated: true, completion: nil)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,答案是将导航控制器包裹到床单中。愚蠢的错误,但可能对某人有帮助。
Ah, the answer is to wrap the nav controller into the sheet. Silly mistake, but might help someone.