Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6206499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:27:39+00:00 2026-05-24T05:27:39+00:00

I have a button on my UI that I would like to flash (turn

  • 0

I have a button on my UI that I would like to flash (turn on and then off again) every 800ms, once the button has been pressed. I do that with the following code:

- (void)flickEmergencyButton {
  // Check whether an emergency is in progress...
  if (model.emergencyInProgress) {
    // ...and if so, flick the state
    self.emergencyButton.selected = !self.emergencyButton.selected;

    // Make this method be called again in 800ms
    [self performSelector:@selector(flickEmergencyButton) withObject:nil afterDelay:0.8];
  } else {
    // ...otherwise, turn the button off
    self.emergencyButton.selected = NO;
  }
}

…which works really well, except: There is a UIScrollView on the UI as well and while the user has his finger down on it and is scrolling around, the button freezes. While I completely understand why that is, I am not sure what to do about it.

The performSelector:withObject:afterDelay message schedules the message to be send on the current thread, which is the main thread, ie. the UI tread and hence does not get to process the message until all other UI activity has come to an end. Correct? But I need to do this on the UI thread as I cannot select/un-select the button on any other thread, right? So what is the solution here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:27:40+00:00Added an answer on May 24, 2026 at 5:27 am

    I would recommend using Core Animation. Try something like this:

    -(void) flash{
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3f];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    
        if( emergency ){       
            // Start flashing
            [UIView setAnimationRepeatCount:1000];
            [UIView setAnimationRepeatAutoreverses:YES];
    
            [btn setAlpha:0.0f];        
        }else{
            // Stop flashing
            [UIView setAnimationBeginsFromCurrentState:YES];
            [UIView setAnimationRepeatCount:1];
    
            [btn setAlpha:1.0f];        
        }
        emergency = !emergency;
        [UIView commitAnimations];
    }
    

    Where btn is declared as

    @property(nonatomic, retain) IBOutlet UIButton *btn;
    

    and emergency is a simple BOOL variable.

    Call flash to start and to stop the animation.

    In this example we animate the alpha attribute for simplicity, but you can do the same with the button backcolor, as Sam said in his answer, or whatever attribute you like.

    Hope it helps.

    UPDATE:

    Regarding making the transition between two images, try calling imageFlash instead of flash:

    -(void) imageFlash{
    
        CABasicAnimation *imageAnimation = [CABasicAnimation animationWithKeyPath:@"contents"];
        [btn setImage:normalState forState:UIControlStateNormal];
    
        if( emergency ){        
            imageAnimation.duration = 0.5f;
            imageAnimation.repeatCount = 1000;
        }else{
            imageAnimation.repeatCount = 1;
        }
    
        imageAnimation.fromValue = (id)normalState.CGImage;
        imageAnimation.toValue = (id)emergencyState.CGImage;    
        [btn.imageView.layer addAnimation:imageAnimation forKey:@"animateContents"];    
        [btn setImage:normalState forState:UIControlStateNormal]; // Depending on what image you want after the animation.
    
        emergency = !emergency;
    }
    

    Where normalState and emergencyState are the images you want to use:

    Declared as:

    UIImage *normalState;
    UIImage *emergencyState;
    

    Assigning the images:

    normalState = [UIImage imageNamed:@"normal.png"];
    emergencyState = [UIImage imageNamed:@"alert.png"];
    

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button that I would like to disable when the form submits
I would like to have a button in my window such that if I
I have a flash music player that I would like to accept a parameter
I have a 'back button' that I would like to stick to the header
I have a button that I'm creating in a UIViewController like so: TOLoginButton* button
I would like to be able to click a button on a flash menu,
I have a Flash/Flex object (Flashlight-VNC), which I would like to dynamically resize to
I'm trying to make a flash video that has an 'exit' button which closes
I have a slide out nav bar that I would like open by default
We have a button that saves asynchronously using AjaxToolKit/C#/.NET. I'm getting this in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.