我正在构建一个简单的激励应用程序 - 我的宠物项目。很简单。当按下按钮时,它会打印一条随机的激励信息。
我希望用户能够按下按钮并在屏幕上裁剪激励信息并将其保存到相机胶卷。
我找到了一个可以完成我想要的教程,但它需要一个完整的截图和一个PARTIAL截图。
我试图修改代码,因此只需要部分屏幕截图。
这是Xcode:
print("SchreenShot")
// Start full screenshot
UIGraphicsBeginImageContext(view.frame.size)
view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
var sourceImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(sourceImage,nil,nil,nil)
//partial Screen Shot
print("partial ss")
UIGraphicsBeginImageContext(view.frame.size)
sourceImage.drawAtPoint(CGPointMake(0, -100))
var croppedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(croppedImage,nil,nil,nil)
此外,在PARTIAL屏幕截图中,它会拍摄"页面的快照"从上到下100像素。如何拍摄页面内容的快照,从页面顶部100像素到页面底部150像素?
很多,很多,非常感谢!
答案 0 :(得分:0)
您的示例代码将视图绘制到图形上下文(快照)中,裁剪并保存。我正在用一些额外的评论来改变它,因为看起来你是这个API的新手
{{1}}