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

  • Home
  • SEARCH
  • 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 6251131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:33:24+00:00 2026-05-24T13:33:24+00:00

I have some animation attached to a custom button in a view controller: –

  • 0

I have some animation attached to a custom button in a view controller:

- (void)viewDidLoad {
    [super viewDidLoad];    

    UIButton *natSenButton = [UIButton buttonWithType:UIButtonTypeCustom];
    natSenButton.frame = CGRectMake(114, 4, 93, 30);
    [natSenButton setTitle:@"Comment" forState:UIControlStateNormal];
    [natSenButton setTitleColor: [UIColor colorWithRed: 255 / 255.0 green:0 blue: 0 alpha:1.0] forState: UIControlStateNormal];
    // text: color with dark red

    [natSenButton addTarget:self action:@selector(displayNativeSentence) forControlEvents:UIControlEventTouchUpInside];
    natSenButton.tag = 333;

    [[natSenButton layer] setCornerRadius:8.0f];
    [[natSenButton layer] setMasksToBounds:YES];

    natSenButton.layer.borderWidth = 2.0; 
    natSenButton.layer.borderColor = 
    [UIColor colorWithRed: 25 / 255.0 green:255/ 255.0 blue: 255/255.0 alpha:1.0].CGColor; 
    // above is light blue color
    natSenButton.layer.backgroundColor = [UIColor colorWithRed: 255 / 255.0 green:255/ 255.0 blue: 255/255.0 alpha:1.0].CGColor;
    // background is white
    //  natSenButton.center = self.center;
    natSenButton.titleLabel.font = [UIFont systemFontOfSize:15.0];

   //Create an animation with pulsating effect
   CABasicAnimation *theAnimation;

   theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
   theAnimation.duration=1.0;   
   theAnimation.repeatCount= 999;
   theAnimation.autoreverses=YES;   
   theAnimation.fromValue=[NSNumber numberWithFloat:1.0]; 
   theAnimation.toValue=[NSNumber numberWithFloat:0.2];

   [natSenButton.layer addAnimation:theAnimation 
                          forKey:@"animateOpacity"]; 
   [self.view addSubview:natSenButton];}

However, sometimes I need to hide this button:

for( UIView *view in self.view.subviews ) {  
        if( [view isKindOfClass:[UIButton class]] ) {  
            if( view.tag == 333 )
                [view setHidden:YES];
        }  
    }

…and then after awhile I need to turn it back on:

for( UIView *view in self.view.subviews ) {  
        if( [view isKindOfClass:[UIButton class]] ) {  
            if( view.tag == 333 )
                [view setHidden:NO];
                [view setNeedsDisplay];  
        }  
    }

This all works fine except when I tap the back button and go back to the parent view controller and then return to this viewController. In those cases, my “view setNeedsDisplay” no longer works and my animation is not on.

Here is where I create my back bar item in the parent view controller:

- (id)init {
    [super initWithStyle:UITableViewStylePlain];

    [[self navigationItem] setTitle:@"Wordplay"];
    UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];      
    temporaryBarButtonItem.title = @"<"; 

    self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
    [temporaryBarButtonItem release];  

    return self;
}

….and here is where the parent view controller pushes back to the problem view controller which has lost its animation:

[[self navigationController] pushViewController:sentenceViewController animated:YES];

Can anyone tell me why I’m losing my animation and how I can turn it back on? Thanks.

  • 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-24T13:33:24+00:00Added an answer on May 24, 2026 at 1:33 pm

    Your view controller’s view in being kept in memory by the navigation controller. I don’t fully understand why but animations are not resumed automatically when you return to a cached view controller. The same thing happens as well after your app goes into the background when implementing multitasking – when the app returns to the foreground nothing is animating.

    You need to remove the animation when you press the back button to go back to your parent view controller and add the animation again when you you return to your view controller with the animating button.

     [natSenButton.layer removeAnimationForKey:@"animateOpacity"];
    

    Where to place the add/remove calls is up to you. You should know what suits you best.

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

Sidebar

Related Questions

I have some custom class BitmapStorage, not attached to any View or whatever -
I have made some custom attached properties that enable me to create a pop
I have some classes layed out like this class A { public virtual void
I have some animation I would like to try, kind of a shopping cart/checkout
So I have some animation blocks to create some very simple animations on my
I'm trying to achieve some animation using jQuery. I have it working but I'm
I have very custom TableView like Add Contact View in iPhone's Contacts. I like
I have an html table that I am trying to add some animation to
I have a storyboard(1) that does some basic animations in 2 seconds. I want
I have some UI in VB 2005 that looks great in XP Style, but

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.