0

I'm working on a new app and I wanted to do a tap to continue opening screen. What I'm doing is scaling a UILabel (created in IB) up and down like this:

note:self.labelShouldScaleUp is a 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];

}

The code works, but when the label is done scaling every time, it jumps to the right or left and then scales the other way. I'm not sure why this is happening.

Thanks in advance for you help.

4

1 回答 1

2

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

}
于 2013-12-09T07:31:04.047 回答