iPhone UILabel动画
我有一个UILabel,当标签中的值发生变化时,我想从另一种颜色高亮显示它的背景色,并存在2,3秒,然后恢复到正常颜色 有人知道怎么做吗iPhone UILabel动画,iphone,ipad,Iphone,Ipad,我有一个UILabel,当标签中的值发生变化时,我想从另一种颜色高亮显示它的背景色,并存在2,3秒,然后恢复到正常颜色 有人知道怎么做吗 添加quartzCore作为框架 添加导入QuartzCore/QuartzCore.h 使用此代码 - (void) initController { UIButton *myButton = [view viewWithTag:1]; // Just reference the button you have [myButton a
- (void) initController
{
UIButton *myButton = [view viewWithTag:1]; // Just reference the button you have
[myButton addTarget:self action:@selector(animateLabel) forControlEvents:UIControlEventTouchUpInside];
}
- (void) animateLabel
{
CABasicAnimation* highlightAnim = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
highlightAnim.toValue = (id)[UIColor blueColor].CGColor;
highlightAnim.duration = 2; // In seconds
highlightAnim.autoreverses = YES; // If you want to it to return to the normal color
[label.layer addAnimation:highlightAnim forKey:nil];
}
- (void) initController
{
UIButton *myButton = [view viewWithTag:1]; // Just reference the button you have
[myButton addTarget:self action:@selector(animateLabel) forControlEvents:UIControlEventTouchUpInside];
}
- (void) animateLabel
{
CABasicAnimation* highlightAnim = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
highlightAnim.toValue = (id)[UIColor blueColor].CGColor;
highlightAnim.duration = 2; // In seconds
highlightAnim.autoreverses = YES; // If you want to it to return to the normal color
[label.layer addAnimation:highlightAnim forKey:nil];
}
嗨,罗恩,非常感谢。我现在要试试。嗨,罗恩,我用按钮试过这个。(单击按钮时执行动画)。但什么也没发生。可能是什么问题?无法使用UIButtonRoundRect类型更改UIButton的颜色,因此无法设置颜色更改的动画。如果你需要一个按钮,你需要创建一个UIButton样式为UIButtonStyleCustom的UIButton,并创建它的外观。不,不,我的意思是,当我点击UIButton时,我是为UILabel做的。对不起,沟通不畅。还是不走运。还有我是如何检测文本更改事件的?我不确定我是否理解,但我更新了答案,可能会回答您的问题。嗨,罗恩,非常感谢。我现在要试试。嗨,罗恩,我用按钮试过这个。(单击按钮时执行动画)。但什么也没发生。可能是什么问题?无法使用UIButtonRoundRect类型更改UIButton的颜色,因此无法设置颜色更改的动画。如果你需要一个按钮,你需要创建一个UIButton样式为UIButtonStyleCustom的UIButton,并创建它的外观。不,不,我的意思是,当我点击UIButton时,我是为UILabel做的。对不起,沟通不畅。还是不走运。还有我是如何检测文本更改事件的?我不确定我是否理解,但我以一种可能回答您问题的方式更新了答案。