开发者

Remove layer from renderInContext

开发者 https://www.devze.com 2023-04-07 16:37 出处:网络
I use this code to make a screenshot, CGFloat breed = 768; CGFloat hoogte = 975; CGSize afmeting = CGSizeMake(breed, hoogte);

I use this code to make a screenshot,

CGFloat breed = 768;
CGFloat hoogte = 975;
CGSize afmeting = CGSizeMake(breed, hoogte);
UIGraphicsBeginImageContext(afme开发者_JS百科ting);
[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?

Now I use textLabel.hidden = YES before making the screenshot and set hidden to NO when finished. 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). 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号