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 7799329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:16:26+00:00 2026-06-02T00:16:26+00:00

In my iOS 5 app I have a custom UIButton that has a red

  • 0

In my iOS 5 app I have a custom UIButton that has a red orb as its image. When the button is tapped I would like the orb to start pulsing/fading between red and green. I have both red and green images and can successfully cross-disolve between the two using the following code:

CABasicAnimation *imageSwitchAnimation = [CABasicAnimation animationWithKeyPath:@"contents"];       
imageSwitchAnimation.fromValue = (id)[UIImage imageNamed:@"red.png"].CGImage;
imageSwitchAnimation.toValue = (id)[UIImage imageNamed:@"green.png"].CGImage;
imageSwitchAnimation.duration = 1.5f;        
[self.button.imageView.layer addAnimation:imageSwitchAnimation forKey:@"animateContents"];

However, I would like the animation to continue forever (well, until I tell it to stop) and also for the animation to reverse and loop. In other words, fade red -> green -> red and then repeat.

I tried putting the animation block above into an endless loop (together with some logic to determine whether the fading should go from red -> green or green -> red) but this just locks-up the entire app.

Other solutions seem to use Cocos2d, which seems fairly heavy-weight since this is the only animation I need in the app (so I don’t want to use such frameworks unless absolutely needed).

Any help would be greatly appreciated.

  • 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-06-02T00:16:28+00:00Added an answer on June 2, 2026 at 12:16 am

    Yes, you can do this, right within CABasicAnimation. The trick is that many of its most important methods are not in the CABasicAnimation Class Reference, or even in its superclasses. CABasicAnimation implements a protocol called CAMediaTiming. See the CAMediaTiming Protocol Reference.

    You want to know about two properties in particular: autoreverses and repeatCount. Both are self-explanatory, but what if you want infinite repeats? From the entry for repeatCount:

    May be fractional. If the repeatCount is 0, it is ignored. Defaults to 0. If both repeatDuration and repeatCount are specified the behavior is undefined.

    Setting this property to HUGE_VALF will cause the animation to repeat forever.

    Can you work it out from there?

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

Sidebar

Related Questions

I have a universal iOS app with a custom view that has three buttons,
I have a Rails app that has 2 clients -- an iOS app reads/writes
I have an iOS app that uses a SQLite DB to store its data
Using iOS 4.3 on an ipad app I have a custom NSOperation that uses
In the iOS app I'm writing, we have an add photo button that's pretty
Assume I have a Cocoa-based Mac or iOS app. I'd like to run a
I have an app for iOS that uses Filesharing to provide the user with
I have an app at the moment that when a button is pushed on
I have developed a small app that stores locally in iOS through archiving an
I have made a custom number pad keypad for my iOS app, but want

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.