Screenshot showing up blank - Swift

后端 未结 2 571
甜味超标
甜味超标 2020-11-29 11:28

Hi I am making a game and I have added a share button to the game. I want the user to be able to share a message, URL, and screenshot along side each other in one message.Th

2条回答
  •  时光取名叫无心
    2020-11-29 12:07

    update: Xcode 8.2.1 • Swift 3.0.2

    You need to add the import statement and this extension to your game scene:

    import UIKit 
    

    extension UIView {
        var snapshot: UIImage? {
            UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0)
            defer { UIGraphicsEndImageContext() }
            drawHierarchy(in: bounds, afterScreenUpdates: true)
            return UIGraphicsGetImageFromCurrentImageContext()
        }
    }
    

    let myImage = view?.snapshot
    

提交回复
热议问题