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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:05:21+00:00 2026-05-27T00:05:21+00:00

I am messing around with a basic CAAnimation example where Im just trying to

  • 0

I am messing around with a basic CAAnimation example where Im just trying to get a CALayer to rotate in a subclass of UIView. I start by making a new CALayer with a red background and inserting it into self.layer. I then make a CAAnimation that is supposed to be triggered on opacity changes and apply it to the CALayer, after which it spins as expected.

Weird thing is that if I try to apply the exact same animation using performSelector:withObject:afterDelay:, the CALayer no longer animates, although its opacity still changes. Even weirder is that if I use performSelector:withObject:afterDelay: to animate self.layer using pretty much the same code, it works.

Any ideas as to what’s going on? Here is my code:

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        point = [[CAGradientLayer alloc] init];

        point.backgroundColor = [UIColor redColor].CGColor;
        point.bounds = CGRectMake(0.0f, 0.0f, 30.0f, 20.0f);
        point.position = CGPointMake(100.0f, 100.0f);

        [self.layer addSublayer:point];
        [point release];    

        [self performSelector:@selector(test) withObject:nil afterDelay:2];
    }
    return self;
}

-(void)test {
    [self spinLayer:point];
    // [self spinLayer:self.layer]; works here
}

-(CAAnimation*)animationForSpinning {
    CATransform3D transform;
    transform = CATransform3DMakeRotation(M_PI/2.0, 0, 0, 1.0);

    CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
    basicAnimation.toValue = [NSValue valueWithCATransform3D:transform];
    basicAnimation.duration = 5;
    basicAnimation.cumulative = NO;
    basicAnimation.repeatCount = 10000;

    return basicAnimation;
}

-(void)spinLayer:(CALayer*)layer {
    CAAnimation *anim = [self animationForSpinning];
    [layer addAnimation:anim forKey:@"opacity"];
    layer.opacity = 0.6;
}

and this is my interface

@interface MyView : UIView {
    CALayer *point;
}

-(void)test;
-(void)spinLayer:(CALayer*)layer;
-(CAAnimation*)animationForSpinning;

@end

Note: I am instantiating this view with a frame equal to [UIScreen mainScreen].applicationFrame from within the app delegate.

  • 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-27T00:05:21+00:00Added an answer on May 27, 2026 at 12:05 am

    Change this:

    [layer addAnimation:anim forKey:@"opacity"];
    

    into this:

    [layer addAnimation:anim
                 forKey:@"notOpacity!"];
    

    What happens is that implicit animation layer.opacity = 0.6 overwrites you explicit animation. This happens because Core Animation uses property names when adding implicit animations.

    (If you move layer.opacity = 0.6 above [layer addAnimation:anim forKey:@"opacity"]; it will also work, but layer.opacity will not get animated.)

    And why it works without delay: because implicit animations are “enabled” only if layer is in the tree and been displayed.

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

Sidebar

Related Questions

I've just started messing around with F# and am trying to do some basic
I'm just messing around with Visual Basic in Visual Studio 2010. Anyone know how
I want to get sql running on my mac. I'm just messing around with
Im just messing around with Ruby on Rails and HTML. This question isn't about
I have a simple app I am messing around with its a basic Master/Details
I am trying to make a basic webclient call to get an xml stream
I am new to programming. I decided to stick with Python after messing around
I've been messing around with my very basic C++ knowledge (been programming for two
I am just messing around with Facebook connect on my local machine. I created
lately I have been messing around with the Silverlight Business Application template to get

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.