UIButton flashing animation

后端 未结 5 2043
粉色の甜心
粉色の甜心 2021-02-03 15:20

I was wondering if it was possible to apply a flashing animation to a UIButton. I have searched but only found the code for a pulse animation which changes the size of my UIButt

5条回答
  •  猫巷女王i
    2021-02-03 15:36

    Try this one:

    call this method when you want blink/flash the button

    blinkTimer=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(toggleButtonImage:) userInfo:nil repeats:YES];
    

    and write this method

    - (void)toggleButtonImage:(NSTimer*)timer
    {
    
        if(toggle)
        {
            [blinkBtn setImage:[UIImage imageNamed:@"ButtonImage.png"] forState: UIControlStateNormal];
        }
        else
        {
            [blinkBtn setImage:[UIImage imageNamed:@"ButtonImage1.png"] forState: UIControlStateNormal];
        }
        toggle = !toggle;
    
    }
    

    in .h write this one

    NSTimer *blinkTimer;
    BOOL toggle;
    

    and invalidate the timer where you want to stop the flashing/blinking

    [blinkTimer invalidate];
    

提交回复
热议问题