gpt4 book ai didi

ios - 全屏模糊 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:05 26 4
gpt4 key购买 nike

我想在触摸“显示 View ”按钮时在我的应用中显示模糊背景。我可以制作模糊背景,但它不是全屏。它显示在选项卡栏和导航栏下方。

这是我的登录屏幕,也是我想要的 (SCLAlertView)

enter image description here

但是我们不能向这个库中添加自定义 View 。所以我想制作一个自定义 View 并向该 View 添加一个进度条。

enter image description here

 @property (nonatomic, strong) UIView *ContentView;
@property (nonatomic, strong) UIImageView *BgView;


_BgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,[[UIScreen mainScreen] applicationFrame].size.width,[[UIScreen mainScreen] applicationFrame].size.height)];

[_BgView setBackgroundColor:[UIColor blackColor]];
_BgView.userInteractionEnabled = YES;
_BgView.alpha = 1.0;
_BgView.tag=7001;

_ContentView = [[UIView alloc] init];
_ContentView.tag=7002;

[self.view addSubview:_ContentView];

_ContentView.backgroundColor = [UIColor whiteColor];
_ContentView.layer.cornerRadius = 2.0f;
_ContentView.layer.masksToBounds = YES;
_ContentView.layer.borderWidth = 0.5f;

当我触摸一个按钮时它调用这个方法

-(void)BlurBg{

float width = self.view.frame.size.width-20;
float height= 120.0;
float x = (self.view.frame.size.width-width)/2;
float y = (self.view.frame.size.height-height)/2;

_ContentView.frame = CGRectMake(x, y, width, height);
UIButton *OkBtn = [[UIButton alloc] initWithFrame:CGRectMake((_ContentView.frame.size.width-(_IcerikView.frame.size.width/3))/2, ((_ContentView.frame.size.height-20)/3)*2, _ContentView.frame.size.width/3, 40)];
OkBtn.backgroundColor=[UIColor greenColor];
[OkBtn setTitle:@"OK" forState:UIControlStateNormal];
OkBtn.layer.cornerRadius = 1;
OkBtn.clipsToBounds = YES;
[OkBtn addTarget:self action:@selector(Sonuc) forControlEvents:UIControlEventTouchUpInside];

[_ContentView addSubview:OkBtn];

[self.view addSubview:_BgView];
[self.view addSubview:_ContentView];
}

-(void) Sonuc{
[[self.view viewWithTag:7001] removeFromSuperview];
[[self.view viewWithTag:7002] removeFromSuperview];
}

最佳答案

Apple 为我们提供了一个很好的资源来复制模糊效果。查看UIBlurEffect

typedef enum {
UIBlurEffectStyleExtraLight,
UIBlurEffectStyleLight,
UIBlurEffectStyleDark
} UIBlurEffectStyle;

关于ios - 全屏模糊 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28690155/

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