在过去,当我想要从一个UILabel文本到另一个UILabel文本做一个漂亮的淡入淡出动画时,我会忽略以下内容:
[UIView beginAnimations:@"fade" context:nil];
[UIView setAnimationDuration:0.25];
myLabel.alpha = 0.0;
myLabel.text = @"Different string";
myLabel.alpha = 1.0;
[UIView commitAnimations];
正如您所知,标签会快速淡出,更改内容,然后淡入。
我在其他应用程序中看到过一些实例,文本看起来似乎很容易消失 - 没有显示出淡出并迅速恢复。
仅仅是我还是有更好的方法来实现这一目标?
感谢。 瑞奇。
答案 0 :(得分:3)
希望这有帮助。
-(void)showButton:(UIButton *)button {
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
opacityAnimation.toValue = [NSNumber numberWithFloat:1.0f];
button.hidden = NO;
[button.layer addAnimation:opacityAnimation
forKey:@"opacity"];
}
-(void)hideButton:(UIButton *)button {
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0f];
opacityAnimation.toValue = [NSNumber numberWithFloat:0.0f];
button.hidden = YES;
[button.layer addAnimation:opacityAnimation
forKey:@"opacity"];
}