我想创建一个非常常见的效果,如下图所示:
说明:我想要实现的效果在于用户单击按钮时出现(滑入)在屏幕底部的 View :您仍然可以看到该 View 后面的屏幕,但它应用了“暗层”(黑色 View ,假设不透明度为 60%)在它的顶部。当用户点击 Block 或 Report abuse(如本例)时,它将执行相应的操作。现在,当用户点击取消时,以及当他点击“深色层”上的任何地方时,都会将他带回屏幕。
我尝试的是:呈现一个新的 View Controller (但它会使用比必要更多的数据),使用覆盖层但我什至没有接近我们通常在应用程序上看到的那种效果。我不确定,但我想说获得这种效果的最佳方式是使用 View ?
有人有想法吗?
谢谢,祝你有美好的一天,
J
最佳答案
您正在寻找名为 UIActionSheet
的 native 元素。它已成为 UIAlertController
的一部分,并且完全符合您的要求。
这里有一些关于如何设置的帮助:
// Create you actionsheet - preferredStyle: .actionSheet
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
// Create your actions - take a look at different style attributes
let reportAction = UIAlertAction(title: "Report abuse", style: .default) { (action) in
// observe it in the buttons block, what button has been pressed
print("didPress report abuse")
}
let blockAction = UIAlertAction(title: "Block", style: .destructive) { (action) in
print("didPress block")
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
print("didPress cancel")
}
// Add the actions to your actionSheet
actionSheet.addAction(reportAction)
actionSheet.addAction(blockAction)
actionSheet.addAction(cancelAction)
// Present the controller
self.present(actionSheet, animated: true, completion: nil)
它应该产生以下输出:
关于 swift : OverlayView that appears at the bottom of the screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40460736/