2 Star 23 Fork 10

小弟调调/swiftui-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
.idoc
assets
example
accessibility
advanced-state
alerts-and-menus
animation
appendix-a
composing-views
containers
cross-platform
data
drawing
forms
images-shapes-media
introduction
lists
presenting-views
quick-start
responding-to-events
stacks-grids-scrollviews
taps-and-gestures
tooling
transforming-views
user-interface-controls
view-layout
working-with-static-text
demo1
demo10
Demo
README.md
demo11
demo12
demo2
demo3
demo4
demo5
demo6
demo7
demo8
demo9
cheat-sheet.md
.gitattributes
.gitignore
LICENSE
README.md
idoc.chapters.yml
idoc.yml
package.json
renovate.json
克隆/下载
README.md 1.81 KB
一键复制 编辑 原始数据 按行查看 历史

如何使用 privacySensitive() 将内容标记为私有?

Updated for Xcode 13 New in macOS 12

SwiftUI 允许我们将视图的某些部分标记为包含敏感信息,这实际上允许我们使用 redaction 更轻松地隐藏或显示它。 要在您的代码中使用此功能,首先将 privacySensitive() 修饰符添加到任何应隐藏的视图,然后在视图层次结构中的较高位置应用 .redacted(reason: .privacy) 修饰符。

例如,如果视图显示在非私有上下文中,这将隐藏用户的信用卡号:

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Card number")
                .font(.headline)

            Text("1234 5678 9012 3456")
                .privacySensitive()
        }
    }
}

默认情况下,隐私敏感上下文被灰色框遮住,但您也可以通过从环境中读取 redaction 原因来提供自定义布局:

struct ContentView: View {
    @Environment(\.redactionReasons) var redactionReasons

    var body: some View {
        VStack {
            Text("Card number")
                .font(.headline)

            if redactionReasons.contains(.privacy) {
                Text("[HIDDEN]")
            } else {
                Text("1234 5678 9012 3456")
            }
        }
    }
}

有时系统会自动应用隐私 redaction,例如如果您的小部件出现在锁定屏幕上(当用户向左滑动时),或者如果他们将 Apple Watch 设置为始终开启并且您的应用程序是可见的——这些都是 您应该将事物标记为隐私敏感的好地方。

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Swift
1
https://gitee.com/jaywcjlove/swiftui-example.git
git@gitee.com:jaywcjlove/swiftui-example.git
jaywcjlove
swiftui-example
swiftui-example
main

搜索帮助