Hide view when take the screenshot in ios

666 Views Asked by At

Hi I am doing one application , in that I am showing one important data in the view n.So whenever user take the screenshot, I want to hide that specific view.So please let me know how to hide the specific view in screenshot.

1

There are 1 best solutions below

0
On

There is a way to achieve this. UITextField has a property isSecureTextEntry that allows to hide the content of text field from being screenshotted. You can make use of that. This is what you can do:

  1. Add an instance of UITextField as subview
  2. Set isSecureTextEntry = true for text field
  3. Set backgroundColor = .clear for text field
  4. Set constraints in a preferred way
  5. If your content has and elements with user interactions (buttons, swipes, etc) - better way to subclass UITextField and override a hitTest(...) function so that your content will receive actions
  6. Find an instance of TextLayoutCanvasView view in subviews of the text field and add your content as a subview of this view

If you need to deal with view controller, then would be good to implement custom vc class, that will manage vc lifecycles (addChild(), didMove(), etc)

Apps with this approach are passing review successfully. Also there are some out of the box solutions on GitHub based on this approach, but in fact can be implemented pretty easy on your own.