gpt4 book ai didi

iOS制作全屏截图问题

转载 作者:行者123 更新时间:2023-11-29 02:17:37 25 4
gpt4 key购买 nike

我有自 View 和 ImageView :

UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
[self setBluredImageView:imageView];
[self addSubview:imageView];

- (UIImage *)takeSnapshotOfView:(UIView *)view
{
CGFloat reductionFactor = 1;
UIGraphicsBeginImageContext(CGSizeMake(view.frame.size.width/reductionFactor, view.frame.size.height/reductionFactor));
[view drawViewHierarchyInRect:CGRectMake(0, 0, view.frame.size.width/reductionFactor, view.frame.size.height/reductionFactor) afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;
}

在方法中,当我想在其他 View 上显示我自己的 View 时,我会这样做:

- (void)showMe; {


AppDelegate* app = [AppDelegate shared];
[app.window addSubview:self];

UIImage *image = [self blurWithImageEffects:[self takeSnapshotOfView:app.window]];

[[self bluredImageView] setImage:image];

[UIView animateWithDuration:0.4 animations:^{

[self setAlpha:1.0];

}];
}

如您所见,我想模糊基于主窗口 View 的“图形上下文”。第一次,当我展示自己的观点时,它工作得很好,但后来,像模糊图像这样的东西相互叠加。

这是我第一次展示我的观点时的图像:

enter image description here

当我多次展示我的观点时,模糊的图像看起来像这样:

enter image description here

所以你可以看到每次模糊的屏幕截图都是不同的,但我使用相同的方法获取屏幕截图并且不更新 View Controller 或其他 ui 部分的内容。

找到的一些方法和图像类别here .

最佳答案

您已经创建了一个模糊循环。当你第二次截取 View 时,bluredImageView 也在屏幕截图中。这就是为什么您会看到效果成倍增加的原因。尝试删除它并仅捕获没有效果的上下文,然后将其添加回来

 - (UIImage *)takeSnapshotOfView:(UIView *)view
{
//Remove the blured image before taking another screenshot.
[self bluredImageView] removeFromSuperview];
CGFloat reductionFactor = 1;

UIGraphicsBeginImageContext(CGSizeMake(view.frame.size.width/reductionFactor, view.frame.size.height/reductionFactor));
[view drawViewHierarchyInRect:CGRectMake(0, 0, view.frame.size.width/reductionFactor, view.frame.size.height/reductionFactor) afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//Add it back now that the effect is done
[self addSubview:[self bluredImageView];
return image;
}

关于iOS制作全屏截图问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28569911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com