gpt4 book ai didi

ios - 在iOS上相当于runTaskLater()

转载 作者:行者123 更新时间:2023-12-01 17:52:38 25 4
gpt4 key购买 nike

使用Android上的Bukkit插件,我可以使用简单的runTaskLater()方法来执行一种方法,先执行一个操作,然后在设定的时间后再执行另一个操作,但是在iOS上,我只知道的performSelector:方法。

我正在尝试做的一个很好的例子是某些文本的淡入淡出动画。假设我希望它先淡入,然后在达到最大不透明度之后再淡出,此刻我必须使用两种单独的方法进行淡入和淡出,这似乎效率不高,但是我无法遇到一个例子或解释如何做到这一点。当然,这可能归因于我对搜索字词的错误选择。

如何将一段代码延迟一定的时间?

最佳答案

您尝试了这两种方法吗?

const float delayInSeconds = 3.0;
NSString *myObject = @"Hello";

// method 1
[self performSelector:@selector(doSomethingWithObject:) withObject:myObject afterDelay:delayInSeconds];

// method 2
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self doSomethingWithObject:myObject];
});

要回答有关标签淡入淡出的问题,请尝试以下操作:
label.alpha = 0.0f;
[UIView animateWithDuration:2.f delay:0.f options:UIViewAnimationOptionCurveEaseIn animations:^{
[label setAlpha:1.f];
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.f delay:1.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
[label setAlpha:0.f];
} completion:nil];
}];

关于ios - 在iOS上相当于runTaskLater(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24983854/

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