ios - 如何动画化 UILabel Scale 重复

标签 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];

}

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

在此先感谢您的帮助。

最佳答案

我认为您应该深入了解 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/

相关文章:

ios - 当来自 NotificationCenter 时,为什么调整标签大小需要延迟才能按预期更新?

ios - 如何在每个切片中制作不同数量的细胞

xcode - 什么是(Xcode : Wildcard AppID) in my iOS Provisioning Portal?

c - 在 Mac 中使用 Xcode 进行 fopen

ios - 使用 AVFoundation 获得裁剪视频的意外结果

objective-c - 特殊字符 NSString

ios - 如何在 SpriteKit 中为关节添加纹理?

ios - 导航 View 推送之前的 UITextField 焦点?

cocoa-touch - iPad 相机连接套件?

javascript - 为什么 react native 元素在 iPhone plus 上的排列方式不同