ios - 如何在 xcode 7、iOS swift 2 中截取 View 的部分屏幕截图?

标签 ios xcode swift cocoa-touch

<分区>

我试图找到正确的代码来通过 xcode 截取当前 View 的屏幕截图,特别是相机,但还没有找到任何东西。我最近才开始编程,也是这个社区的新手。

最佳答案

您可以使用以下代码截取全屏:

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
}

关于ios - 如何在 xcode 7、iOS swift 2 中截取 View 的部分屏幕截图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34923046/

相关文章:

ios - Xcode 11.2.1 线程清理程序 abort_with_payload

ios - 我们可以从后台线程更新UI吗?

c# - Xamarin.IOS 导入现有 Storyboard

ios - 使用超链接在 IOS 中实现可本地化的字符串

ios - 如何从 Collection View 中打开 View Controller ?

ios - UIAlertView 问题与 session.dataTaskWithRequest

iOS:NSString 丢失 URL,显示 (null)

iPhone 应用程序 - 咖啡杯识别

swift - 碰撞 --> 不要与颜色开关等任何东西发生碰撞

iphone - 应用程序图标未在 iPhone 模拟器中显示