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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:26:06+00:00 2026-05-30T04:26:06+00:00

Here is my code section below, I wish implement a animation on opacity to

  • 0

Here is my code section below, I wish implement a animation on opacity to show a breath effect on a button.

NSString* kAnimation = @"animation";
NSString* kBreath = @"breath";
NSString* kHide = @"hide";
NSString* kOpacity = @"opacity";

- (void) breathAnimation {

      ................

      CAKeyframeAnimation *darkblueBreathAnimation = [CAKeyframeAnimation animationWithKeyPath:kOpacity];

      NSArray *darkblueOpacityValues = [NSArray arrayWithObjects:[NSNumber numberWithFloat:1.0f],
                                        [NSNumber numberWithFloat:0.0f],
                                        [NSNumber numberWithFloat:1.0f],
                                        nil];

      NSArray *darkblueOpacityTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
                                       [NSNumber numberWithFloat:0.5f],
                                       [NSNumber numberWithFloat:1.0f],
                                       nil];

      [darkblueBreathAnimation setValues:darkblueOpacityValues];

      [darkblueBreathAnimation setKeyTimes:darkblueOpacityTimes];

      [darkblueBreathAnimation setDuration:1.0f];


      [darkblueBreathAnimation setRepeatCount:2];

      [darkblueBreathAnimation setFillMode:kCAFillModeRemoved];

      [darkblueBreathAnimation setCalculationMode:kCAAnimationLinear];

      [darkblueBreathAnimation setRemovedOnCompletion:YES];

      [darkblueBreathAnimation setDelegate:self];

      [darkBlueLayer_ addAnimation:darkblueBreathAnimation forKey:kBreath];

      CAKeyframeAnimation *lightblueBreathAnimation = [CAKeyframeAnimation animationWithKeyPath:kOpacity];

      NSArray *lightblueOpacityValues = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
                                        [NSNumber numberWithFloat:1.0f],
                                        [NSNumber numberWithFloat:0.0f],
                                        nil];

      NSArray *lightblueOpacityTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
                                       [NSNumber numberWithFloat:0.5f],
                                       [NSNumber numberWithFloat:1.0f],
                                       nil];

      [lightblueBreathAnimation setValues:lightblueOpacityValues];

      [lightblueBreathAnimation setKeyTimes:lightblueOpacityTimes];

      [lightblueBreathAnimation setDuration:1.0f];

      [lightblueBreathAnimation setRepeatCount:2];

      [lightblueBreathAnimation setFillMode:kCAFillModeRemoved];

      [lightblueBreathAnimation setCalculationMode:kCAAnimationLinear];

      [lightblueBreathAnimation setRemovedOnCompletion:YES];

      [lightblueBreathAnimation setDelegate:self];

      [lightblueBreathAnimation setValue:kBreath forKey:kAnimation];

      [lightBlueLayer_ addAnimation:lightblueBreathAnimation forKey:kBreath];

    ...................

}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

  NSString* value = (NSString*)[anim valueForKey:kAnimation];

  NSLog(@"Roby: value = %@", value);

  if ([[anim valueForKey:kAnimation] isEqualToString:kHide]) {

    //TODO

  } else if ([[anim valueForKey:kAnimation] isEqualToString:kBreath]) {

    [self removeBreathAnimationLayers];

  }
}

Actually speaking, I need know the breath animation stop to remove the two CALayer. But, I got flag is NO in animationDidStop(), it indicates animation is not complete properly, and no breath animation shown.
Then, I tried to not invoke [self removeBreathAnimationLayers] to remove the two CALayer, the animation works well.

Does anyone have any suggestion on this issue? I really need know the animation stop successfully to do something else.

Appreciate for your reply. Thanks a lot!

-Roby

  • 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-30T04:26:10+00:00Added an answer on May 30, 2026 at 4:26 am

    I got the way to fix this issue by adding [CATransaction begin] and [CATransaction commit] at the beginning and ending of the animation section.

    Then, the code is like below:

    - (void) breathAnimation {
    
    ................
    [CATransaction begin];
    
    CAKeyframeAnimation *darkblueBreathAnimation = [CAKeyframeAnimation animationWithKeyPath:kOpacity];
    
    NSArray *darkblueOpacityValues = [NSArray arrayWithObjects:[NSNumber numberWithFloat:1.0f],
                                        [NSNumber numberWithFloat:0.0f],
                                        [NSNumber numberWithFloat:1.0f],
                                        nil];
    
    NSArray *darkblueOpacityTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
                                       [NSNumber numberWithFloat:0.5f],
                                       [NSNumber numberWithFloat:1.0f],
                                       nil];
    
    [darkblueBreathAnimation setValues:darkblueOpacityValues];
    
    [darkblueBreathAnimation setKeyTimes:darkblueOpacityTimes];
    
    [darkblueBreathAnimation setDuration:1.0f];
    
    [darkblueBreathAnimation setRepeatCount:2];
    
    [darkblueBreathAnimation setFillMode:kCAFillModeRemoved];
    
    [darkblueBreathAnimation setCalculationMode:kCAAnimationLinear];
    
    [darkblueBreathAnimation setRemovedOnCompletion:YES];
    
    [darkblueBreathAnimation setDelegate:self];
    
    [darkBlueLayer_ addAnimation:darkblueBreathAnimation forKey:kBreath];
    
    CAKeyframeAnimation *lightblueBreathAnimation = [CAKeyframeAnimation animationWithKeyPath:kOpacity];
    
    NSArray *lightblueOpacityValues = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
                                        [NSNumber numberWithFloat:1.0f],
                                        [NSNumber numberWithFloat:0.0f],
                                        nil];
    
    NSArray *lightblueOpacityTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
                                       [NSNumber numberWithFloat:0.5f],
                                       [NSNumber numberWithFloat:1.0f],
                                       nil];
    
    [lightblueBreathAnimation setValues:lightblueOpacityValues];
    
    [lightblueBreathAnimation setKeyTimes:lightblueOpacityTimes];
    
    [lightblueBreathAnimation setDuration:1.0f];
    
    [lightblueBreathAnimation setRepeatCount:2];
    
    [lightblueBreathAnimation setFillMode:kCAFillModeRemoved];
    
    [lightblueBreathAnimation setCalculationMode:kCAAnimationLinear];
    
    [lightblueBreathAnimation setRemovedOnCompletion:YES];
    
    [lightblueBreathAnimation setDelegate:self];
    
    [lightblueBreathAnimation setValue:kBreath forKey:kAnimation];
    
    [lightBlueLayer_ addAnimation:lightblueBreathAnimation forKey:kBreath];
    
    [CATransaction commit];
    
    ...................
    
    }
    
    - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    
    NSString* value = (NSString*)[anim valueForKey:kAnimation];
    
    NSLog(@"Roby: value = %@", value);
    
    if ([[anim valueForKey:kAnimation] isEqualToString:kHide]) {
    
    //TODO
    
    } else if ([[anim valueForKey:kAnimation] isEqualToString:kBreath]) {
    
    [self removeBreathAnimationLayers];
    
    }
    }
    

    I’m a newbie on core animation, wish this would help someone who run into this issue.

    -Roby

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

Sidebar

Related Questions

I am trying to toggle the parent <li> and <button> styles. Here my code
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code from MSDN . I don't understand why the work isn't just
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
enter code here I have a table on SQL server 2005 with bigint primary
The code here is X++. I know very little about it, though I am
enter code here Hi All, I have a simple windows service application that connects
Edit: The code here still has some bugs in it, and it could do
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var

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.