gpt4 book ai didi

iOS:UIButton 的动画文本位置不起作用

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

我想让按钮的文本在按下“错误答案”按钮时“消失”。

在我的问题演示代码中,我的项目有两个按钮,一个带有 socket “myBtn”,没有任何操作,另一个带有 TouchUpInside 操作。 Action 处理程序如下所示:

- (IBAction)goPressed:(UIButton*)sender {

//UILabel *lbl = self.myBtn.titleLabel;
UILabel *lbl = sender.titleLabel;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
lbl.center = CGPointMake(lbl.center.x-60, lbl.center.y);
lbl.alpha = 0;
}
completion:nil];
}

我正在尝试为两个属性设置动画:“alpha”从 1 变为 0,文本位置向左移动 60 点。

如果我取消注释第一行“UILAbel”并注释第二行,那么按下按钮会在第二个按钮中运行一个漂亮的动画。

但是,如果我保留显示的代码,尝试为按下的按钮本身的文本设置动画,alpha 动画效果很好,但位置没有改变。

非常感谢任何帮助!

最佳答案

我在 iOS7 上见过这种问题。在 IBAction 中运行良好的动画在 iOS7 上不起作用。我不得不将我所有的动画代码移动到不同的方法并在延迟后调用选择器。如果您这样做,您的代码将正常工作 -

- (IBAction) goPressed:(UIButton*)sender {
[self performSelector:@selector(animateButton:) withObject:sender afterDelay:0.1];
}

- (void) animateButton:(UIButton *) button{
UILabel *lbl = button.titleLabel;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
lbl.center = CGPointMake(lbl.center.x-60, lbl.center.y);
lbl.alpha = 0;
}
completion:nil];
}

关于iOS:UIButton 的动画文本位置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19354540/

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