ios開發之滑動長圖截全屏應用

來源:互聯網
上載者:User

標籤:.com   current   height   poi   option   log   render   send   capture   

最近做項目遇到要求截取圖片長度超出手機螢幕,即可滑動的長圖截屏,這裡簡單說一下解決思路,下面附帶Demo。

,當我們要截全屏時,將滑動視圖的frame以及位移量記錄下來,然後將滑動視圖位移量設為0,frame改為滑動視圖的

contentSize,然後產生圖片進行儲存,代碼實現如下:

// 下面方法,第一個參數表示地區大小。第二個參數表示是否是非透明的。如果需要顯示半透明效果,需要傳NO,否則傳YES。第三個參數就是螢幕密度了,調整清晰度。    UIGraphicsBeginImageContextWithOptions(scroll.contentSize, YES, [UIScreen mainScreen].scale);        CGPoint savedContentOffset = scroll.contentOffset;    CGRect savedFrame = scroll.frame;    scroll.contentOffset = CGPointZero;    scroll.frame = CGRectMake(0, 0, scroll.contentSize.width, scroll.contentSize.height);    [scroll.layer renderInContext: UIGraphicsGetCurrentContext()];    image = UIGraphicsGetImageFromCurrentImageContext();    scroll.contentOffset = savedContentOffset;    scroll.frame = savedFrame;        UIGraphicsEndImageContext();

Demo:https://github.com/zk1947/CaptureScreen

 

ios開發之滑動長圖截全屏應用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.