我在 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 方式,但性能非常糟糕。
最佳答案
来自:https://developer.apple.com/forums/thread/736112
更改:
field.layer.sublayers?.first?.addSublayer(self.layer)
至:
field.layer.sublayers?.last?.addSublayer(self.layer)
关于ios - 使用 'isSecureTextEntry' 阻止屏幕截图在 iOS 17 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77140471/