I must do the operation right here is to limit the precise ui with another ui when person makes an attempt to take the display shot, however right here when i attempt to take the display shot the purple blocker view seems however the saved picture has the precise ui content material methods to overcome this.
May anybody assist me to getting this attainable, like would possibly you seen any of the cost or safety functions with does’t permits to take the display shot however right here it must be allowed however we have to override the precise ui presents within the partucular view.
class HomeViewController: UIViewController {
non-public var greetLabel: UILabel!
non-public let navigator: HomeNavigator
init(navigator: HomeNavigator) {
self.navigator = navigator
tremendous.init(nibName: nil, bundle: nil)
setupTabBar()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been carried out")
}
override func viewDidLoad() {
tremendous.viewDidLoad()
setupNavigationBar()
setupViews()
setupConstraints()
}
override func viewWillAppear(_ animated: Bool) {
tremendous.viewWillAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(handleScreenshot), title: UIApplication.userDidTakeScreenshotNotification, object: nil)
}
override func viewDidDisappear(_ animated: Bool) {
tremendous.viewDidDisappear(animated)
NotificationCenter.default.removeObserver(self, title: UIApplication.userDidTakeScreenshotNotification, object: nil)
}
@objc func handleScreenshot() {
let blockerView = ScreenshotBlockerView(body: UIScreen.major.bounds)
if let keyWindow = UIApplication.shared.home windows.first(the place: { $0.isKeyWindow }) {
keyWindow.addSubview(blockerView)
}
DispatchQueue.major.asyncAfter(deadline: .now() + 1.0) {
self.removeScreenshotBlockerView()
}
}
func removeScreenshotBlockerView() {
if let keyWindow = UIApplication.shared.home windows.first(the place: { $0.isKeyWindow }) {
for subview in keyWindow.subviews {
if subview is ScreenshotBlockerView {
subview.removeFromSuperview()
}
}
}
}
non-public func setupNavigationBar() {
navigationItem.title = "House"
self.navigationItem.largeTitleDisplayMode = .by no means
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.backBarButtonItem = UIBarButtonItem(title: "",type: .plain,goal: nil,motion: nil)
}
non-public func setupTabBar() {
let tabBarItem = UITabBarItem(title: "House", picture: UIImage(systemName: "home") , tag: 0)
tabBarItem.selectedImage = UIImage(systemName: "home.fill")
self.tabBarController?.tabBar.barTintColor = UIColor.blue
self.tabBarItem = tabBarItem
}
non-public func setupViews() {
view.backgroundColor = .white
let greetLabel = UILabel()
greetLabel.numberOfLines = 0
greetLabel.font = UIFont.systemFont(ofSize: 18 , weight: UIFont.Weight.semibold)
greetLabel.textColor = UIColor.black
greetLabel.translatesAutoresizingMaskIntoConstraints = false
greetLabel.textual content = AppConstants.shared.greetLabelText(forType: .itemConstant)
self.greetLabel = greetLabel
view.addSubview(greetLabel)
}
non-public func setupConstraints() {
NSLayoutConstraint.activate([
self.greetLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
self.greetLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
}
}
class ScreenshotBlockerView: UIView {
override init(body: CGRect) {
tremendous.init(body: body)
backgroundColor = UIColor.purple
}
required init?(coder: NSCoder) {
tremendous.init(coder: coder)
}
}