如何在xcode 7中使用iOS视图的部分截图,iOS swift 2?
问题描述:
我试图找到正确的代码,通过Xcode拍摄当前视图的截图,特别是相机,但还没有找到任何东西。我已经开始编程,最近也是这个社区的新手。如何在xcode 7中使用iOS视图的部分截图,iOS swift 2?
答
您可以通过使用此代码充分屏幕截图:
func captureView(view: UIView) -> UIImage {
var screenRect: CGRect = UIScreen.mainScreen().bounds
UIGraphicsBeginImageContext(screenRect.size)
var ctx: CGContextRef = UIGraphicsGetCurrentContext()
UIColor.blackColor().set()
CGContextFillRect(ctx, screenRect)
view.layer.renderInContext(ctx)
var newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
需要明确的是,这将需要您的应用程序的视图(S)的截图,但没有任何东西外你的应用程序中。 Apple关闭了iOS 9系统或其他应用程序绘制的屏幕截图的截图功能。 –