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.
Asked
Active
Viewed 280 times
-1
-
Does this answer your question? [Exclude View from Screenshot](https://stackoverflow.com/questions/35967638/exclude-view-from-screenshot) – Frankenstein May 06 '20 at 08:23
-
@Frankenstein That does not answer the question: we're talking about user screenshots here, not about taking them programmatically. – Andrey Tarantsov Apr 14 '21 at 08:13
1 Answers
0
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:
- Add an instance of
UITextField
as subview - Set
isSecureTextEntry = true
for text field - Set
backgroundColor = .clear
for text field - Set constraints in a preferred way
- 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 - 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.

lobstah
- 871
- 7
- 12