For example, when you press the "share button", assume that a modal that takes a screenshot of the screen and posts it on Twitter etc. comes out from the bottom. Maybe you can copy and paste.
func takeScreenShot() {
let width = CGFloat(UIScreen.main.bounds.size.width)
//Calculate the height considering the part you do not want to copy, such as the status bar
let height = CGFloat(UIScreen.main.bounds.size.height/1.3)
let size = CGSize(width: width, height: height)
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
//Export to view
self.view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
screenShotImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
}
//When you press the share button
@IBAction func share(_ sender: Any) {
//Take a screenshot
takeScreenShot()
let items = [screenShotImage] as [Any]
//Share on the activity view
let activityVC = UIActivityViewController(activityItems: items, applicationActivities: nil)
//Modal appears
present(activityVC, animated: true, completion: nil)
}
Recommended Posts