Ced*_*rie 158
您可以使用自动转换.它工作得非常好:
// Add transition (must be called after myLabel has been displayed)
CATransition *animation = [CATransition animation];
animation.duration = 1.0;
animation.type = kCATransitionFade;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[myLabel.layer addAnimation:animation forKey:@"changeTextTransition"];
// Change the text
myLabel.text = newText;
Run Code Online (Sandbox Code Playgroud)
如果已显示myLabel,则此代码有效.如果不是myLabel.layer将为nil并且动画将不会添加到对象中.
在Swift 4中将是:
let animation: CATransition = CATransition()
animation.duration = 1.0
animation.type = kCATransitionFade
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
myLabel.layer.add(animation, forKey: "changeTextTransition")
Run Code Online (Sandbox Code Playgroud)
Ant*_*nko 26
它运作良好!
Objective-C的
[UIView transitionWithView:self.label
duration:.5f
options:UIViewAnimationOptionCurveEaseInOut |
UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.label.text = rand() % 2 ? @"111!" : @"42";
} completion:nil];
Run Code Online (Sandbox Code Playgroud)
迅速
UIView.transitionWithView(label, duration: 0.25, options: [.CurveEaseInOut, .TransitionCrossDissolve], animations: {
self.label.text = (arc4random() % 2 == 0) ? "111" : "222"
}, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我发现了一个很棒的引擎,用于使用称为PRTween的各种不同的计时函数来补间值.安装类并沿这些行创建一些代码:
- (IBAction)tweenValue
{
[[PRTween sharedInstance] removeTweenOperation:activeTweenOperation];
PRTweenPeriod *period = [PRTweenPeriod periodWithStartValue:0.0 endValue:100.0 duration:1.0];
activeTweenOperation = [[PRTween sharedInstance] addTweenPeriod:period
target:self
selector:@selector(update:)
timingFunction:&PRTweenTimingFunctionCircOut];
}
- (void)update:(PRTweenPeriod*)period
{
self.animatingView.center = CGPointMake(period.tweenedValue + 100.0, 200.0);
self.valueLabel.text = [NSString stringWithFormat:@"%.2f", period.tweenedValue];
}
Run Code Online (Sandbox Code Playgroud)
为我服务.:)
如果你想让它用新的数字向上和向下计数推动前一个数字(如股票代码或其他东西):
let animation = CATransition()
animation.removedOnCompletion = true
animation.duration = 0.2
animation.type = kCATransitionPush
animation.subtype = newValue > value ? kCATransitionFromTop : kCATransitionFromBottom
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
valueLabel.layer.addAnimation(animation, forKey:"changeTextTransition")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34328 次 |
| 最近记录: |