SnapshotSafeView icon indicating copy to clipboard operation
SnapshotSafeView copied to clipboard

How I can apply this to any View from storyboard?

Open MallikarjunH opened this issue 2 years ago • 1 comments

I added one UIView in UIViewController (Please check the screenshot below) Once a user tries to take a screenshot, that View should not appear in the screenshot. How I can do it? How I can apply your library/code to any specific view (UIView) ?

I tried the following code, from that code my View itself not showing in iPhone, once I run the code.

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var safeView1: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
   
        var hiddenFromScreenshotButtonController2 = ScreenshotProtectController(content: safeView1)
        hiddenFromScreenshotButtonController2.setupContentAsHiddenInScreenshotMode()
    }
}

Simulator Screen Shot - iPhone 14 Pro - 2022-09-19 at 17 36 39

MallikarjunH avatar Sep 19 '22 12:09 MallikarjunH

Hi, @MallikarjunH, you should apply all layout operations to container. https://github.com/Stampoo/SnapshotSafeView#uikit

       var hiddenFromScreenshotButtonController2 = ScreenshotProtectController(content: safeView1)
       hiddenFromScreenshotButtonController2.setupContentAsHiddenInScreenshotMode()
       view.addSubview(hiddenFromScreenshotButtonController2.container) // U should adding container to view
           [
            hiddenFromScreenshotButtonController2.container.topAnchor.constraint(equalTo: view.topAnchor, constant: 65),
            hiddenFromScreenshotButtonController2.container.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 65),
            hiddenFromScreenshotButtonController2.container.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -65),
            hiddenFromScreenshotButtonController2.container.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -65)
        ].forEach { $0.isActive = true } // Layout control apply to container

Stampoo avatar Sep 26 '22 10:09 Stampoo