Skip to content

Instantly share code, notes, and snippets.

@ashishkakkad8
Created April 23, 2023 10:56
Show Gist options
  • Save ashishkakkad8/695e0b1828f699ed538bcf1a01920cc7 to your computer and use it in GitHub Desktop.
Save ashishkakkad8/695e0b1828f699ed538bcf1a01920cc7 to your computer and use it in GitHub Desktop.
Screenshot Prevent for ScrollView
extension UIView {
func preventScrollViewScreenshotRecursive() {
guard superview != nil else {
for subview in subviews {
subview.preventScrollViewScreenshotRecursive()
}
return
}
let guardTextField = UITextField()
guardTextField.backgroundColor = .red
guardTextField.translatesAutoresizingMaskIntoConstraints = false
guardTextField.tag = Int.max
guardTextField.isSecureTextEntry = true
addSubview(guardTextField)
guardTextField.isUserInteractionEnabled = false
sendSubviewToBack(guardTextField)
layer.superlayer?.addSublayer(guardTextField.layer)
guardTextField.layer.sublayers?.first?.addSublayer(layer)
guardTextField.centerYAnchor.constraint(
equalTo: self.centerYAnchor
).isActive = true
guardTextField.centerXAnchor.constraint(
equalTo: self.centerXAnchor
).isActive = true
}
}
@awnigharbia
Copy link

It's not working on ios 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment