Flashing problems with UILabel using basic animation

I would like to have text that blinks using basic animation. I added the following code, but can't see the text not vibrate.

// 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 understand what's wrong with my approach.

+3
source share
1 answer

Kind of a 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 alpha should be set to 0, it should be part of the animation block, not the final one.

+3
source

All Articles