Benj
Benj

Reputation: 794

View home screen in iOS application (Swift)

How can I make the background of a UIView translucent so that the user can see their (blurred) home screen?

If this is not possible, perhaps I can screenshot the home screen and add a translucency effect. In this case, how do I take a screenshot of the user's home screen?

Apple has tight privacy views (which I support) so I understand that none of the above may be permitted.

Upvotes: 0

Views: 576

Answers (1)

Harsh Surati
Harsh Surati

Reputation: 11

1. For having background of previous UIViewController, present next controller with presentationStyle as overFullScreen.

let vc = ViewController()
vc.modalPresentationStyle = .overFullScreen
self.present(vc, animated: true, completion: nil)

If need translucent effect use,

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView)

2. To take screenshot.

func takeScreenshot(view: UIView) -> UIImageView {
     UIGraphicsBeginImageContext(view.frame.size)
     view.layer.render(in: UIGraphicsGetCurrentContext()!)
     let image = UIGraphicsGetImageFromCurrentImageContext()
     UIGraphicsEndImageContext()
     UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)
     return UIImageView(image: image)   
}

let view = HomeScreen().view
let image = taketakeScreenshot(view)

Upvotes: 1

Related Questions