gpt4 book ai didi

ios - 闪烁动画导致 View 卡住

转载 作者:行者123 更新时间:2023-11-29 02:43:14 24 4
gpt4 key购买 nike

我正在尝试创建一种方法来使我的应用程序中的某些图标闪烁。但是当我使用这段代码时:

-(void)blinkIcon : (UIButton *)theIcon
{
for (int i = 0; i < 6 ; i++)
{
if (theIcon.hidden)
{
theIcon.hidden = NO;
}
else
{
theIcon.hidden = YES;
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.3]];
}
theIcon.hidden = NO;
}

效果不是很好,因为图标“卡住了”几秒钟,仅此而已。该过程必须结束于:

theIcon.hidden = NO; 

最佳答案

我刚刚写了这个方法,它需要一个按钮来完成我认为你所说的眨眼的意思。

- (void)blinkButton:(UIButton *)button {
CGFloat newAlpha = button.alpha == 1.0 ? 0.1 : 1.0;
[UIView animateWithDuration:0.5 animations:^{
button.alpha = newAlpha;
} completion:^(BOOL finished) {
[self blinkButton:button];
}];
}

它产生以下结果:

https://www.dropbox.com/s/48vfpgn1cw6mj17/blink2.mov?dl=0

如果您不想在将来某个时候停止它,您可以这样做 - 我设置了一个条形按钮项用于测试调用 stopBlinking 方法:

- (void)blinkButton:(UIButton *)button {
// if we shouldn't be blinking and the button is currently not
// totally faded in, fade it all the way in
if (!_shouldBlink && button.alpha != 1.0) {
[UIView animateWithDuration:0.5 animations:^{
button.alpha = 1.0;
}];
}

// otherwise we should continue blinking
else {
CGFloat newAlpha = button.alpha == 1.0 ? 0.1 : 1.0;
[UIView animateWithDuration:0.5 animations:^{
button.alpha = newAlpha;
} completion:^(BOOL finished) {
[self blinkButton:button];
}];
}
}

- (void)stopBlinking {
_shouldBlink = NO;
}

这会产生这样的结果:

https://www.dropbox.com/s/sbwol1ac710t6nw/stop.mov?dl=0

关于ios - 闪烁动画导致 View 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25477026/

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