【问题标题】:How to animate UILabel Scale Repeatedly如何为 UILabel Scale 重复设置动画
【发布时间】:2013-09-11 19:46:06
【问题描述】:

我正在开发一个新应用,我想点按以继续打开屏幕。我正在做的是像这样向上和向下缩放 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];

}

代码有效,但是当标签每次完成缩放时,它会向右或向左跳转,然后以另一种方式缩放。我不确定为什么会这样。

提前感谢您的帮助。

【问题讨论】:

    标签: ios xcode cocoa-touch animation uilabel


    【解决方案1】:

    我认为您应该进一步了解 UIView 动画选项。这是一个示例。您可能想要使用 UIViewAnimationOptions 之一。关于这个主题还有另一个SO Question。您还可以查看 Apple 文档参考 page 的 Animating Views with Block Objects 部分中的方法

    -(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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多