我想知道我的iPhone应用程序如何利用特定的屏幕截图UIView作为UIImage.
我试过这段代码,但我得到的只是一张空白图片.
UIGraphicsBeginImageContext(CGSizeMake(320,480));
CGContextRef context = UIGraphicsGetCurrentContext();
[myUIView.layer drawInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
myUIView尺寸为320x480,并且有一些子视图.这样做的正确方法是什么?
在我的iPad应用程序中,我想制作UIView占据屏幕重要部分的屏幕截图.不幸的是,子视图非常嵌套,因此需要很长时间才能制作屏幕截图并使页面随后变形.
有没有比"通常"更快的方式?
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我想避免缓存或重构我的观点.