久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何截取 Scrollview 的所有內容?

How to make a screenshot of all the content of a Scrollview?(如何截取 Scrollview 的所有內容?)
本文介紹了如何截取 Scrollview 的所有內容?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想創建一個 UIScrollView 的屏幕截圖,它應該包含滾動視圖的全部內容,甚至包括當前對用戶不可見的內容.為此,我嘗試了以下兩種方法:

func snapShot(view:UIView) ->UIImage {UIGraphicsBeginImageContextWithOptions(view.bounds.size, true, 0);view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true);讓圖像 = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();返回圖像;}func snapShotScrollView(scrollView:UIScrollView) ->UIImage {讓 bounds = scrollView.bounds;scrollView.bounds.size = scrollView.contentSize;讓圖像 = snapShot(scrollView);scrollView.bounds = 邊界;返回圖像;}

但生成的圖像仍然只是顯示滾動視圖中當前對用戶可見的那些視圖元素.但我想查看所有視圖.

我該怎么做?

編輯

我也試過了:

func 快照() ->圖像?{變種圖像:UIImage?UIGraphicsBeginImageContext(scrollView.contentSize)讓 savedContentOffset = scrollView.contentOffset讓 savedFrame = scrollView.frame;scrollView.contentOffset = CGPoint.zero;scrollView.frame = CGRect(x: 0, y: 0, width: scrollView.contentSize.width, height: scrollView.contentSize.height);scrollView.layer.render(in: UIGraphicsGetCurrentContext()!)圖像 = UIGraphicsGetImageFromCurrentImageContext();scrollView.contentOffset = savedContentOffset;scrollView.frame = savedFrame;UIGraphicsEndImageContext();返回圖片}

編輯 2

我的 UIScrollView 放置在 UIView 內,并且確實包含 UIStackView.該視圖被設計為一個彈出視圖,因此看起來像是彈出了一個對話.我第一次編輯的代碼示例在一個空白的 UIViewController 中工作,只有一個 UIScrollView 但不在上述星座中.

解決方案

I want to create a screenshot of a UIScrollView which should contain the whole content of the scroll view, even that content, which is currently not visible to the user. For that I tried the following two methods:

func snapShot(view:UIView) -> UIImage {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, true, 0);

    view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true);

    let image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;
}

func snapShotScrollView(scrollView:UIScrollView) -> UIImage {
    let bounds = scrollView.bounds;

    scrollView.bounds.size = scrollView.contentSize;

    let image = snapShot(scrollView);

    scrollView.bounds = bounds;

    return image;
}

But the resulting image is still just showing those view elements inside the scroll view which are currently visible to the user. But I want to see all views.

How can I do that?

EDIT

I also tried:

func snapshot() -> UIImage? {
    var image: UIImage?

    UIGraphicsBeginImageContext(scrollView.contentSize)

    let savedContentOffset = scrollView.contentOffset
    let savedFrame = scrollView.frame;

    scrollView.contentOffset = CGPoint.zero;
    scrollView.frame = CGRect(x: 0, y: 0, width: scrollView.contentSize.width, height: scrollView.contentSize.height);

    scrollView.layer.render(in: UIGraphicsGetCurrentContext()!)
    image = UIGraphicsGetImageFromCurrentImageContext();

    scrollView.contentOffset = savedContentOffset;
    scrollView.frame = savedFrame;

    UIGraphicsEndImageContext();

    return image
}

Edit 2

My UIScrollView is placed inside a UIView and does contain a UIStackView. The View is designed as a popover view so that it looks like a dialogue is popping up. The code sample from my first edit is working in a blank UIViewController with only one UIScrollView but not in the mentioned constellation.

解決方案

To Swift from this answer, adding a test ViewController:

class ScreenShotTestViewController: UIViewController {

    var scrollView: UIScrollView!

    override func viewDidLoad() {
        super.viewDidLoad()
        scrollView = UIScrollView(frame: CGRect(origin: CGPoint.zero, size: view.frame.size))
        scrollView.contentSize = CGSize(width: view.frame.size.width, height: view.frame.size.height * 2)
        scrollView.backgroundColor = UIColor.yellow
        view.addSubview(scrollView)

        let label = UILabel(frame: CGRect(x: 0.0, y: view.frame.size.height * 1.5, width: view.frame.size.width, height: 44.0))
        label.text = "Hello World!"
        scrollView.addSubview(label)

        let screenShot = snapshot()
    }

    func snapshot() -> UIImage?
    {      
        UIGraphicsBeginImageContext(scrollView.contentSize)

        let savedContentOffset = scrollView.contentOffset
        let savedFrame = scrollView.frame

        scrollView.contentOffset = CGPoint.zero
        scrollView.frame = CGRect(x: 0, y: 0, width: scrollView.contentSize.width, height: scrollView.contentSize.height)

        scrollView.layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext()

        scrollView.contentOffset = savedContentOffset
        scrollView.frame = savedFrame

        UIGraphicsEndImageContext()

        return image
    }
}

Results in an image of the complete content, including subviews:

這篇關于如何截取 Scrollview 的所有內容?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 中文字幕国产视频 | 久久男人 | 久久国产精品久久久久 | 一级黄色夫妻生活 | 欧美一区二区三区在线观看 | 国产精品视频免费观看 | 午夜国产一级片 | 91久久精品日日躁夜夜躁国产 | 中文字幕 亚洲一区 | 国精产品一区一区三区免费完 | 超碰97人人人人人蜜桃 | 伊人免费视频二 | 国产高清在线 | 日韩午夜精品 | 男人天堂久久 | 国产91精品在线 | 欧美色影院 | 免费高清成人 | 中文字幕三区 | 亚洲欧美激情网 | 精品久久久久久久 | 国产精品天堂 | 在线成人av | 狠狠骚 | 国产欧美精品一区二区色综合 | 99re视频在线免费观看 | 欧美日韩一区在线播放 | 婷婷丁香在线视频 | 欧美日韩国产一区二区三区不卡 | 国产综合精品一区二区三区 | 欧美一级二级视频 | 懂色一区二区三区免费观看 | 国产在线一区二区 | 午夜影院在线观看 | 久久精彩视频 | 91色在线| 色视频免费 | 国产精品高潮呻吟久久 | 精品少妇一区二区三区在线播放 | 日本免费一区二区三区视频 | 国产一区二区三区www |