【问题标题】:How to create iOS simple text animation?如何制作iOS简单的文字动画?
【发布时间】:2013-01-08 15:31:29
【问题描述】:

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

【问题讨论】:

  • 我以前只使用 NSTimer 完成过。而且效果很好。

标签: ios animation xcode4.5


【解决方案1】:

如果你只是想闪词,你可以使用NSTimer或者只是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 或其他动画构造结合使用。

【讨论】:

  • 太棒了!请注意,如果您希望此动画即使在其他 UI 元素正在运行时也继续更新(例如 UIScrollLView),您需要使用 NSRunLoopCommonModes 安排重复过程。
【解决方案2】:

通常核心动画是最好的方法。查看the documentation

【讨论】:

  • 我认为不是。如果他真的想在标签从文本变为空白或返回时为过渡设置动画,animateWithDuration 会容易得多。但我认为这不是问题所在。
  • 好的,什么是事件/调度程序,用于在显示新页面时(对于 NNString 字:arrayWords)开始显示?无需用户交互......谢谢
猜你喜欢
  • 2015-06-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
  • 2016-11-22
  • 2016-02-24
  • 1970-01-01
  • 2022-09-23
  • 1970-01-01
相关资源
最近更新 更多