使用“isSecureTextEntry”防止屏幕截图在 iOS 17 上不起作用

问题描述 投票:0回答:1

我在 iOS 16 上使用“isSecureTextEntry”来解决这个问题,https://stackoverflow.com/a/76390952/22598343

extension UIView {
    func makeSecure() {
        DispatchQueue.main.async {
            let field = UITextField()
            field.isSecureTextEntry = true
            self.addSubview(field)
            field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
            field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
            self.layer.superlayer?.addSublayer(field.layer)
            field.layer.sublayers?.first?.addSublayer(self.layer)
        }
    }
}

它现在看起来无法在 iOS 17 上运行。还有其他解决办法吗?

我尝试过 DRM 方式,但性能非常糟糕。

ios screenshot ios17
1个回答
5
投票

来自:https://developer.apple.com/forums/thread/736112

改变:

field.layer.sublayers?.first?.addSublayer(self.layer)

至:

field.layer.sublayers?.last?.addSublayer(self.layer)
© www.soinside.com 2019 - 2024. All rights reserved.