UIView更快的截屏至UIImage(特別是ipad3)

UIView截屏會應用於很多的場景,如:

1、具有紙書翻頁動作效果的代碼廣泛用於iOS閱讀類應用
2、保存當前場景

代碼如下:

- (UIImage *) p_w_picpathByRenderingView:(UIView*) theView {

    CGFloat oldAlpha = theView.alpha;

    theView.alpha = 1;

       UIGraphicsBeginImageContext(theView.bounds.size);

[theView.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

    theView.alpha = oldAlpha;

return resultingImage;

}


 
但如果處理不好,這裏截屏有時候速度會不太理想。

一個建議的解決方案是,讓UIView的layer採用CATiledLayer

CATiledLayer會很好的cache你的View.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章