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

如何截取 Scrollview 的所有內(nèi)容?

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

問(wèn)題描述

我想創(chuàng)建一個(gè) UIScrollView 的屏幕截圖,它應(yīng)該包含滾動(dòng)視圖的全部?jī)?nèi)容,甚至包括當(dāng)前對(duì)用戶不可見(jiàn)的內(nèi)容.為此,我嘗試了以下兩種方法:

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 = 邊界;返回圖像;}

但生成的圖像仍然只是顯示滾動(dòng)視圖中當(dāng)前對(duì)用戶可見(jiàn)的那些視圖元素.但我想查看所有視圖.

我該怎么做?

編輯

我也試過(guò)了:

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 內(nèi),并且確實(shí)包含 UIStackView.該視圖被設(shè)計(jì)為一個(gè)彈出視圖,因此看起來(lái)像是彈出了一個(gè)對(duì)話.我第一次編輯的代碼示例在一個(gè)空白的 UIViewController 中工作,只有一個(gè) 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:

這篇關(guān)于如何截取 Scrollview 的所有內(nèi)容?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設(shè)置滾動(dòng)視圖內(nèi)容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動(dòng)滾動(dòng))
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 模擬器上運(yùn)行時(shí),使用 iOS 6.0 SDK 并為 iOS 5 Target 構(gòu)建會(huì)導(dǎo)致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 亚洲精品国产成人 | 久久久99精品免费观看 | 国产区一区二区三区 | 国产免费观看久久黄av片涩av | www.99热.com| 日本一区二区高清视频 | 久久亚洲国产精品日日av夜夜 | 成人免费在线观看视频 | 九九爱这里只有精品 | 精品欧美 | 亚洲成人精品久久 | 欧美日韩久 | 欧美性生交大片免费 | 91人人爽 | 黄色av网站在线观看 | 亚洲综合色视频在线观看 | 久在草| 国产精品视频一区二区三区 | 亚洲第一在线 | 国产三级 | 婷婷亚洲综合 | 精品1区| 麻豆av电影网| 国产成人精品一区二区 | 91成人在线视频 | 2018中文字幕第一页 | 91影库| 天天操天天插 | 色.com| 国产精品欧美一区二区三区不卡 | 国产大学生情侣呻吟视频 | 在线电影日韩 | 国产精品一区在线观看 | 久久久久国产精品www | av毛片| 欧美激情一区二区三级高清视频 | 特黄特黄a级毛片免费专区 av网站免费在线观看 | 亚洲午夜精品视频 | 精品久久久久久久久久久久 | 欧美激情精品久久久久 | 成人欧美 |