1

简单的 iOS 文本/标签动画的最佳解决方案是什么?细节:用户需要在iOS屏幕上看到一个标签,其文本从数组de 10-15个单词,一个单词被白屏分隔,显示时间为800-900 ms,显示时间为白色屏幕为 500 毫秒。有一种注意力测试。

4

2 回答 2

3

如果你只想闪词,你可以使用NSTimeror just performSelector

@interface ViewController ()

@property (nonatomic, strong) NSArray *words;
@property (nonatomic) NSUInteger wordIndex;

@end

@implementation ViewController

static CGFloat const kWordShowInterval = 0.8;
static CGFloat const kWordHideInterval = 0.4;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.words = @[@"one", @"two", @"three", @"four"];
    self.wordIndex = 0;

    [self showWord];
}

- (void)showWord
{
    if (self.wordIndex >= [self.words count])
        return;

    self.wordLabel.text = self.words[self.wordIndex];

    [self performSelector:@selector(hideWord)
               withObject:nil
               afterDelay:kWordShowInterval];
}

- (void)hideWord
{
    self.wordLabel.text = nil;

    self.wordIndex++;
    if (self.wordIndex < [self.words count])
    {
        [self performSelector:@selector(showWord)
                   withObject:nil
                   afterDelay:kWordHideInterval];
    }
    else
    {
        // all done, go ahead and invoke whatever you want to do when done presenting the words
    }
}

@end

如果你想对文本的出现或消失做一些动画(例如淡入或淡出),你可以将它与一个animateWithDuration或其他动画结构结合起来。

于 2013-01-08T16:18:34.933 回答
0

通常核心动画是最好的方法。查看文档

于 2013-01-08T15:49:08.517 回答