1
我現在試圖呈現uiview。我可以通過像這樣的東西來正確渲染整個uiview。uiview只渲染特定區域xcode(不是通過裁剪)
[toBeRecorded.layer renderInContext:UIGraphicsGetCurrentContext()];
不過,我想知道,只渲染特定區域這樣的事情(不通過裁剪..但只渲染特定區域)。我應該怎麼做?
我現在試圖呈現uiview。我可以通過像這樣的東西來正確渲染整個uiview。uiview只渲染特定區域xcode(不是通過裁剪)
[toBeRecorded.layer renderInContext:UIGraphicsGetCurrentContext()];
不過,我想知道,只渲染特定區域這樣的事情(不通過裁剪..但只渲染特定區域)。我應該怎麼做?
下面是答案,我寫了這個方法,完美的作品:
+ (UIImage*) screenShotTheArea:(CGRect)area inView:(UIView*)view{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(CGSizeMake(area.size.width, area.size.height), NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(view.bounds.size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, -area.origin.x, -area.origin.y);
[view.layer renderInContext:c];
UIImage* thePrintScreen = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return thePrintScreen;
}
Oh..thanks..it工作:d –
我很樂意幫助你! :) – incmiko