简体   繁体   English

从renderInContext移除图层

[英]Remove layer from renderInContext

I use this code to make a screenshot, 我使用此代码制作屏幕截图,

CGFloat breed = 768;
CGFloat hoogte = 975;
CGSize afmeting = CGSizeMake(breed, hoogte);
UIGraphicsBeginImageContext(afmeting);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];

There are some layers (buttons and textlabels) that I don't want in the image. 我不需要图像中的某些层(按钮和文本标签)。 Is there a way to remove some layers from renderincontext? 有没有一种方法可以从renderincontext中删除某些图层?

Now I use textLabel.hidden = YES before making the screenshot and set hidden to NO when finished. 现在,我在制作屏幕截图之前使用textLabel.hidden = YES,并在完成时将其设置为NO。 Also for the buttons and other labels. 也用于按钮和其他标签。

All the buttons and labels have their own layers. 所有按钮和标签都有自己的图层。 All these layers can be rendered to some graphical context. 所有这些层都可以呈现给某些图形上下文。 Now you are generating your self.view.layer as image, you could try to make another view that would consist only of items you do want to render (keeping your labels and buttons separate in another view that would overlap your "picture view") or you can in fact render all components one by one not including your buttons (though that would probably be more work than you do now). 现在,您将self.view.layer生成为图像,您可以尝试制作另一个仅包含您要渲染的项目的视图(将标签和按钮分开放置在另一个与“图片视图”重叠的视图中)或者,实际上,您可以一一呈现所有组件(不包括按钮)(尽管这可能比您现在做的工作还要多)。 If you will consider making one view on top of another, bear in mind that all the inputs (touches and events) in the top view must be sent to bottom view if you want it to react accordingly. 如果要考虑将一个视图放在另一个视图之上,请记住,如果要使其做出相应反应,则必须将顶视图中的所有输入(触摸和事件)发送到底视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM