gpt4 book ai didi

ios - 当用户单击 UI 按钮时创建阴影(或模糊)?

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

我在 Buttom 中有一个 One Uibutton。当用户单击该按钮时,会显示一个 uiview 动画,如从按钮到顶部的弹出窗口。这是我的代码

-(void)viewDidLoad 
{
[super viewDidLoad];
self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height);
}

- (IBAction)animated:(id)sender
{
if(_isAnimated)
{
[UIView animateWithDuration:0.3
delay:0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 520, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height);
}
completion:^(BOOL finished){
}];
_isAnimated=NO;
}
else
{
[UIView animateWithDuration:0.3
delay:0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height);
}
completion:^(BOOL finished)
{

}];
_isAnimated=YES;
}
}

Uiview 动画效果很好,但是当 uiview 出现时,背景 View 会像 uiactionsheet 一样创建阴影(或模糊),并且在完成动画后背景 View 是清晰的。我不知道如何实现。请帮助我我是 iOS 新手...

最佳答案

您可以在背景中添加一个UIView,并在storyboard 中将其backgroundcolor 设置为黑色和alpha 0.5。然后通过动画将其 alpha 从 0.5 更改为 0。您还可以添加 UITapGestureRecognizer 来检测对其的点击并在用户点击外部时关闭 View 。

-(void)viewDidLoad 
{
[super viewDidLoad];
self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height);
}

- (IBAction)animated:(id)sender
{
if(_isAnimated)
{
[UIView animateWithDuration:0.3
delay:0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 520, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height);
//showing background view here
self.viewBackground.alpha = 0.5;
}
completion:^(BOOL finished){
}];
_isAnimated=NO;
}
else
{
[UIView animateWithDuration:0.3
delay:0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height);
//dismissing background view here
self.viewBackground.alpha = 0.0;
}
completion:^(BOOL finished)
{

}];
_isAnimated=YES;
}
}

用于检测外部的点击并关闭您的 View :

创建一个UITapGestureRecognizer:

@interface ViewController ()
{
UITapGestureRecognizer *tapGesture;
}

ViewDidLoad中初始化:

-(void)viewDidLoad 
{
//defining your gesture method
tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTapGesture:)];

//adding gesture recognizer on the background view
[self.backgroundView addGestureRecognizer:tapGestureRecognizer];
}

在你的手势识别器方法中:

-(void)handleSingleTapGesture:(UITapGestureRecognizer *)tapGestureRecognizer
{
[UIView animateWithDuration:0.3
animations:^{
//dismissing background view here
self.viewBackground.alpha = 0.0;
}
completion:^(BOOL finished){
}];
}

希望这对您有所帮助。

关于ios - 当用户单击 UI 按钮时创建阴影(或模糊)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42135135/

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