简体   繁体   English

截屏时,如何删除按钮?

[英]When I take screenshot, How to remove the button?

When I take screenshot, How to remove the button? 截屏时,如何删除按钮? I am using this code for screen shot 我正在使用此代码进行屏幕截图

CGImageRef originalImage = UIGetScreenImage();
CGImageRef videoImage = CGImageCreateWithImageInRect(originalImage, CGRectMake(0, 66, 320, 230));            
UIImage *snapShotImage = [UIImage imageWithCGImage:videoImage];
UIImageWriteToSavedPhotosAlbum(snapShotImage, nil, nil, nil);
CGImageRelease(originalImage);                
CGImageRelease(videoImage);  

在此处输入图片说明

remove your button just before taking the screen shots, you can store its frame in CGRect and add it again after UIGraphicsEndImageContext(); 在拍摄屏幕快照之前删除按钮,您可以将其框架存储在CGRect中,并在UIGraphicsEndImageContext()之后再次添加它 line 线

 CGRect rect = yourButton.frame; // store your buttons frame
[yourButton removeFromSuperView];
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

yourButton = [UIButton buttonWithType:UIButtonTypeCustom];

[yourButton setFrame:rect];
[yourButton setImage:[UIImage imageNamed:@"yourButtonImage.png"] forState:UIControlStateNormal];
[yourButton addTarget:self action:@selector(yourButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view yourButton];

If the button image is included in the other image this could get really complicated (then I would recommend you to enter fullscreen and take the screenshot). 如果按钮图像包含在其他图像中,则可能会变得非常复杂(然后,我建议您进入全屏模式并获取屏幕截图)。

If the button image isn't included directly in the other image (eg. just a HTML overlay) than you could also easy hide it with css. 如果按钮图像未直接包含在其他图像中(例如,仅是HTML叠加层),那么您也可以使用CSS轻松隐藏该按钮图像。

But perhaps there are better ways than making screenshots in iOS… 但是也许有比在iOS中制作屏幕截图更好的方法……

Hi you can make a view like backView and then on button click call this code.... 嗨,您可以制作一个像backView的视图,然后在按钮上单击以调用此代码。

-(IBAction)screenShotBtnPress :(id)sender  
{

    UIGraphicsBeginImageContext(self.view.window.frame.size);
    [BackView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}  

This code take the screenShot of BackView, make IBOutlet for this view and then connect this.... 该代码采用BackView的screenShot,为此视图创建IBOutlet,然后将其连接。

在截屏之前隐藏该按钮。

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

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