Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would recommend using Core Animation. Try something like this:</p> <pre><code>-(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]; } </code></pre> <p>Where btn is declared as</p> <pre><code>@property(nonatomic, retain) IBOutlet UIButton *btn; </code></pre> <p>and emergency is a simple BOOL variable.</p> <p>Call flash to start and to stop the animation.</p> <p>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.</p> <p>Hope it helps.</p> <p><strong>UPDATE:</strong></p> <p>Regarding making the transition between two images, try calling <code>imageFlash</code> instead of <code>flash</code>:</p> <pre><code>-(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; } </code></pre> <p>Where <code>normalState</code> and <code>emergencyState</code> are the images you want to use:</p> <p>Declared as:</p> <pre><code>UIImage *normalState; UIImage *emergencyState; </code></pre> <p>Assigning the images:</p> <pre><code>normalState = [UIImage imageNamed:@"normal.png"]; emergencyState = [UIImage imageNamed:@"alert.png"]; </code></pre> <p>Good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload