Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blinking a UILabel issue using core animation

Tags:

label

ios5

I would like to have a text that blink using core animation. I have put the following code but I don't see the text neither see it blinking.

// Create a blinking text
UILabel* labelText = [[UILabel alloc] initWithFrame:CGRectMake(355, 490, 400, 50)];
labelText.text = @"Tap to start";
labelText.backgroundColor = [UIColor clearColor];
[self.view addSubview:labelText];


void (^animationLabel) (void) = ^{
        labelText.alpha = 1;
};
void (^completionLabel) (BOOL) = ^(BOOL f) {
        labelText.alpha = 0;
};

NSUInteger opts =  UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat;
[UIView animateWithDuration:1.f delay:0 options:opts
                     animations:animationLabel completion:completionLabel];

any idea? I really don't see what is wrong in my approach.

like image 370
tiguero Avatar asked Feb 18 '26 22:02

tiguero


1 Answers

Kind of stupid mistake but good to know in the future - the code should be

void (^animationLabel) (void) = ^{
        labelText.alpha = 0;
    };
    void (^completionLabel) (BOOL) = ^(BOOL f) {
        labelText.alpha = 1;
    }; 

since the alpha have to be set to 0 it should be part of the animation block not the completion one.

like image 146
tiguero Avatar answered Feb 21 '26 15:02

tiguero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!