swift : OverlayView that appears at the bottom of the screen

标签 swift view overlay uialertcontroller uiactionsheet

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

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/

相关文章:

swift - 按属性对关系中的对象进行排序?

swift - TableView Controller : Replace Table with Login or Error-Screen

java - Android:如果未在 XML 中定义,则通过 ID 查找 View 对象

html - 如何在多个不同大小的图像上叠加文字? CSS

javascript - 如何在javascript中叠加图像?

swift - 如何将结构体初始化中的属性设置移动到另一个方法中

swift - UITabBarController自定义页面顶栏颜色swift

ios - 点击时展开 UICollectionView 及其单元格

view - 你如何访问 couchbase View 中的值?

android - 在 Android 上覆盖 ImageView