jel*_*sh6 3 overlay view uiactionsheet swift uialertcontroller
我想创建一个非常普通的效果,如下图所示:
说明:我要实现的效果包括一个视图,该视图在用户单击按钮时出现在屏幕底部(滑入):您仍然可以看到该视图后面的屏幕,但是它应用了“深色层” (例如黑度为60%的不透明度)的顶部。当用户单击“阻止”或“报告弃权”时(如本例所示),它将执行相应的操作。现在,当用户单击“取消”时,以及当他单击“深色层”上的任意位置时,都将使他回到屏幕上。
我想做的是:使用覆盖层展示一个新的视图控制器(但是它将使用比必要的更多的数据),但是我什至没有达到我们通常在应用程序上看到的那种效果。我不确定,但我想说要获得这种效果的最好方法是使用视图?
请问有人有主意吗?
谢谢,祝你有美好的一天,
Ĵ
您正在寻找名为的本机元素UIActionSheet。它已成为的一部分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)
Run Code Online (Sandbox Code Playgroud)
它应该产生以下输出:
| 归档时间: |
|
| 查看次数: |
875 次 |
| 最近记录: |