如何重复动画UILabel量表

时间:2013-09-11 19:46:06

标签: ios xcode cocoa-touch animation uilabel

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

}

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

先谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

我认为你应该仔细看看UIView动画选项。这是一个例子。您可能想要使用UIViewAnimationOptions之一。关于这个主题还有另一个SO Question。您还可以查看Apple文档参考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;

}