Ios 截图和分享?
我已经在没有导航栏的情况下完成了完整屏幕截图的编码,但我也不想要“激励我”按钮 还有,如果有人知道如何将作物截图分享到Facebook 以下是屏幕截图的代码:Ios 截图和分享?,ios,swift,uigraphicscontext,Ios,Swift,Uigraphicscontext,我已经在没有导航栏的情况下完成了完整屏幕截图的编码,但我也不想要“激励我”按钮 还有,如果有人知道如何将作物截图分享到Facebook 以下是屏幕截图的代码: UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size,false,0); self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true) var image:UII
UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size,false,0);
self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
确保“激励我”按钮不在拍摄屏幕截图的视图层次结构中。将其移动到单独的视图中,然后使用与您已有的代码相同的代码。这正是你想要的 或者,如果要裁剪整张照片,可以使用以下选项,请替换按钮高度中的值以适合:
var heightOfButton: CGFloat = 100
var size = UIScreen.mainScreen().bounds.size
size.height -= heightOfButton
UIGraphicsBeginImageContextWithOptions(size,false,0);
self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
只需在截图之前隐藏
ui按钮
,然后在截图之后取消隐藏即可
func screenshot() {
// Hide button
myButton.alpha = 0.0
// Take screenshot
UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size,false,0)
self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
// Unhide button
myButton.alpha = 1.0
}
要将您的图像共享到Facebook,您可以使用
另一方面,您不需要使用
代码>在Swift的每行末尾。我们能不能只写一个代码,裁剪一幅图像,然后保存到照片中library@swimnny89谢谢你的回答。很好,但是宽度不太好,所以如何更改宽度你可以使用size.width=//在这里输入值来更改宽度。在size.height-=按钮高度之后和UIGraphicsBegin之前在线上执行此操作…没问题,很高兴我能提供帮助。如果我想在facebook上共享此作物,您也能帮我吗@斯文尼89