標籤:.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開發之滑動長圖截全屏應用