gpt4 book ai didi

iphone - UIButtons 在动画 block 期间不会淡出

转载 作者:行者123 更新时间:2023-11-28 18:04:24 25 4
gpt4 key购买 nike

我有一组 UIButtons 和 UILabels,我想在选择一个按钮并且它是正确的按钮时淡出。

我尝试了很多方法(在代码块中对它们进行了注释),但只有 UILabel 淡出。我在这里缺少什么?

-(IBAction)answerButtonPressed:(UIButton *)sender {
NSLog(@"Game Question Answer Pressed: %i", sender.tag);
NSLog(@"%@", sender.titleLabel.text);

int selectedAnswer =0;
selectedAnswer = [question.answer intValue];

if (selectedAnswer == sender.tag) {
NSLog(@"GameQ %@ is the correct answer", sender.titleLabel.text);

//self.toggleView;

[labelA setAlpha:0];
[labelB setAlpha:0];
[labelC setAlpha:0];
[labelD setAlpha:0];


/*
[buttonA setAlpha:0];
[buttonB setAlpha:0];
[buttonC setAlpha:0];
[buttonD setAlpha:0];

[buttonA setHidden:YES];
[buttonB setHidden:YES];
[buttonC setHidden:YES];
[buttonD setHidden:YES];
*/
[sender setAlpha:1];
[sender setHidden:NO];

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];

[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{buttonA.alpha = 0;}
completion:nil];

[UIView setAnimationDelegate:[UIApplication sharedApplication]];
[UIView setAnimationDidStopSelector:@selector(endIgnoringInteractionEvents)];

[UIView commitAnimations];

此后我清理了该方法并仅使用一种类型的动画 block 。 UIButton 仍然不会淡出,但标签会淡出。这是我的动画 block :

        [UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{buttonA.alpha = 0;}
completion:nil];

[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{labelA.alpha = 0;}
completion:nil];

最佳答案

我会即时结合我注意到的事情。您正在组合两种类型的动画技术。新旧:

要么:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];

buttonA.alpha = 0;

[UIView commitAnimations];

或者(并且首选,因为它是“现代”方式)

[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{buttonA.alpha = 0;}
completion:nil];

如您所见,将两者结合起来可能会导致 block 被调用多次,因为第一种动画技术插入了第二种动画技术。基本上,将许多动画放入队列中,非常快地将按钮淡入 0。

此外,默认情况下(至少使用 block )默认禁用用户交互。无需明确执行。

关于iphone - UIButtons 在动画 block 期间不会淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8862680/

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