我有一系列想要在UILabel
上執行的動畫,所以我查找了iOS7中添加的UIViewKeyframeAnimations
。更改UILabel的文本使它在使用UIViewKeyframeAnimations時重新出現
什麼,我想做一個簡單的版本是:
- 淡出的UILabel與持續時間0.5秒
- 等待1秒
淡入的UILabel與新文本與持續時間0.5秒
NSTimeInterval duration = 2; [UIView animateKeyframesWithDuration:duration delay:0 options:UIViewKeyframeAnimationOptionAllowUserInteraction | UIViewAnimationOptionOverrideInheritedOptions animations:^{ [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5/duration animations:^{ self.label.alpha = 0; }]; [UIView addKeyframeWithRelativeStartTime:1.5/duration relativeDuration:0.5/duration animations:^{ self.label.text = [@(arc4random_uniform(4000)) stringValue]; self.label.alpha = 1; }]; } completion:nil];
結果是標籤文本是淡出並以新的文字重新出現,然後再次消失並再次消失。
結果的視頻:Animation Failure
乾杯 莫滕
沒關係啊,所以我的選擇是1.回覆到舊animateWithDuration 2.介紹一個臨時'UILabel'和'UIImageView' 3.使用一些第三方承諾框架掃。選項1對長動畫非常混亂。 – mbogh 2014-10-16 11:56:21