gpt4 book ai didi

swift : OverlayView that appears at the bottom of the screen

转载 作者:可可西里 更新时间:2023-11-01 00:36:06 24 4
gpt4 key购买 nike

我想创建一个非常常见的效果,如下图所示:

view that appears at the bottom of the screen

说明:我想要实现的效果在于用户单击按钮时出现(滑入)在屏幕底部的 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)

它应该产生以下输出:

enter image description here

关于 swift : OverlayView that appears at the bottom of the screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40460736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com