如何拍摄pickerViewController和UIView的屏幕截图? [英] How to take a screenshot of a pickerViewController and UIView?

查看:112
本文介绍了如何拍摄pickerViewController和UIView的屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TableView,在ViewController上显示了PickerViewController. ViewController会显示一些图像和一个按钮,而不是触发一个动作.我希望此操作将屏幕快照作为Apple提供的屏幕快照. 这是我的代码:

I have a TableView who presents a PickerViewController on a ViewController. The ViewController show some Images and a button than triggering an action. I want that this action takes a screenshot as the screenshot that is provided by Apple. Here is my code:

@IBAction func share(){

UIGraphicsBeginImageContext(view.frame.size)
    UIGraphicsBeginImageContext(thePicker.view.frame.size)
    view.layer.render(in: UIGraphicsGetCurrentContext()!)
    thePicker.view.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    let activity = UIActivityViewController(activityItems: [image], applicationActivities: nil)
    present(activity, animated: true, completion: nil)
}

此图片是使用Apple提供的屏幕快照(侧面+主页按钮)的结果 此图片是我的代码的结果

推荐答案

func ScreenCapturing() 
{
  UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.main.scale)
    view.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
}

这篇关于如何拍摄pickerViewController和UIView的屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆