如何将字符添加到 iOS 和 Objective-C 动画的 UILabel?
How can I add characters to an UILabel animated in iOS with Objective-C?
我试过的
我创建了一个循环遍历 NSMutableArray
的递归函数,每次都会浏览这个动画博客。这段代码调用了这个方法,因为我认为 UILabel
上的动画不起作用的问题是,它不是 运行 在主线程上。
[self performSelectorOnMainThread:@selector(writeText:)
withObject:_arrayAllLabels
waitUntilDone:YES];
动画有一个 completion
块,它还检查动画是否完成,然后继续调用相同的函数。此外,我添加了一个额外的动画博客,但没有任何东西能够平滑地向标签添加字符。
[UIView animateWithDuration:1.5f
delay:1.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
//adding next character to text attribute of UILabel
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.0f
animations:^{
if ( finished ){
[self performSelectorOnMainThread:@selector(writeText:)
withObject:_arrayAllLabels
waitUntilDone:YES];
}
} completion:nil];
}];
长什么样子
我搜索的结果不对
我已经四处寻找了一段时间,并试图找到与我的问题相关的问题,但我发现的所有内容都只指向一个方向,将 UILabel
的文本更改为另一个文本,没有一个字符
- 计算器。com/questions/26402062/changing-the-text-of-a-uilabel-makes-it-reappear-when-using-uiviewkeyframeanimat
- 计算器。com/questions/26703501/fade-between-text-in-a-uilabel-with-delay
有人可以帮忙吗?
UILabel 的 setText 方法不可设置动画。 animateWithDuration:completion:
只会对帧、边界、中心、变换中的变化进行动画处理...请在此处查看有关动画的 Apple 文档以获取动画列表 属性:https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html
对于您的问题,您必须忘记使用 animateWithDuration:completion:
并自己创建动画,例如使用 NSTimer 每 x 秒执行一次 addLetter: 方法...
我试过的
我创建了一个循环遍历 NSMutableArray
的递归函数,每次都会浏览这个动画博客。这段代码调用了这个方法,因为我认为 UILabel
上的动画不起作用的问题是,它不是 运行 在主线程上。
[self performSelectorOnMainThread:@selector(writeText:)
withObject:_arrayAllLabels
waitUntilDone:YES];
动画有一个 completion
块,它还检查动画是否完成,然后继续调用相同的函数。此外,我添加了一个额外的动画博客,但没有任何东西能够平滑地向标签添加字符。
[UIView animateWithDuration:1.5f
delay:1.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
//adding next character to text attribute of UILabel
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.0f
animations:^{
if ( finished ){
[self performSelectorOnMainThread:@selector(writeText:)
withObject:_arrayAllLabels
waitUntilDone:YES];
}
} completion:nil];
}];
长什么样子
我搜索的结果不对
我已经四处寻找了一段时间,并试图找到与我的问题相关的问题,但我发现的所有内容都只指向一个方向,将 UILabel
的文本更改为另一个文本,没有一个字符
- 计算器。com/questions/26402062/changing-the-text-of-a-uilabel-makes-it-reappear-when-using-uiviewkeyframeanimat
- 计算器。com/questions/26703501/fade-between-text-in-a-uilabel-with-delay
有人可以帮忙吗?
UILabel 的 setText 方法不可设置动画。 animateWithDuration:completion:
只会对帧、边界、中心、变换中的变化进行动画处理...请在此处查看有关动画的 Apple 文档以获取动画列表 属性:https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html
对于您的问题,您必须忘记使用 animateWithDuration:completion:
并自己创建动画,例如使用 NSTimer 每 x 秒执行一次 addLetter: 方法...