我正在开发一款新应用,我想点击一下以继续打开屏幕。我正在做的是像这样上下缩放 UILabel(在 IB 中创建):
注意:self.labelShouldScaleUp 是一个 BOOL。
-(void)animateLabel{
if(self.labelShouldScaleUp){
[UIView animateWithDuration:1 animations:^(void){
self.clickToContinueLabel.transform=CGAffineTransformScale(self.clickToContinueLabel.transform, 2, 2);
} completion:^(BOOL finished){
self.labelShouldScaleUp=NO;
}];
}
if(!self.labelShouldScaleUp){
[UIView animateWithDuration:1 animations:^(void){
self.clickToContinueLabel.transform=CGAffineTransformScale(self.clickToContinueLabel.transform, 0.5, 0.5);
} completion:^(BOOL finished){
self.labelShouldScaleUp=YES;
}];
}
[self performSelector:@selector(animateLabel) withObject:nil afterDelay:1.05];
}
代码有效,但是当标签每次完成缩放时,它会跳到右边或左边,然后以另一种方式缩放。我不确定为什么会这样。
在此先感谢您的帮助。
最佳答案
我认为您应该深入了解 UIView 动画选项。这是一个示例。您可能想要使用 UIViewAnimationOptions 之一。还有一个SO Question关于这个话题。您还可以查看 Apple 文档引用的使用 block 对象动画化 View 部分中的方法 page
-(void)animateDisplayText
{
[self.view bringSubviewToFront:self.happyMessageLabel];
self.happyMessageLabel.alpha = 0.0f;
self.happyMessageLabel.textColor = [UIColor yellowColor];
self.happyMessageLabel.shadowColor = [UIColor redColor];
self.happyMessageLabel.text = [self.controller.data randomHappyMessage];
self.happyMessageLabel
.font = kFontHappyMessageLabel;
// set font size which you want instead of 35
self.happyMessageLabel.transform = CGAffineTransformScale(self.happyMessageLabel.transform, 0.25, 0.25);
[UIView animateWithDuration:1.5 delay: 0.0 options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
self.happyMessageLabel.alpha = 1.0f;
self.happyMessageLabel.transform = CGAffineTransformScale(self.happyMessageLabel.transform, 0.35, 0.35);
self.happyMessageLabel.transform = CGAffineTransformScale(self.happyMessageLabel.transform, 5, 5);
} completion:^(BOOL finished){
[UIView animateWithDuration:2.5 animations:^{
self.happyMessageLabel.transform = CGAffineTransformScale(self.happyMessageLabel.transform, 5, 5);
self.happyMessageLabel.transform = CGAffineTransformScale(self.happyMessageLabel.transform, 0.35, 0.35);
self.happyMessageLabel.alpha = 0.3f;
[self.view sendSubviewToBack:self.happyMessageLabel];
}];
}];
self.happyMessageLabel.transform = CGAffineTransformIdentity;
}
关于ios - 如何动画化 UILabel Scale 重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18749932/