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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:45:04+00:00 2026-06-02T06:45:04+00:00

Using Obj.-c for iPhone 5.1 in Xcode 4.3.2; I create an array of CALayers,

  • 0

Using Obj.-c for iPhone 5.1 in Xcode 4.3.2; I create an array of CALayers, all from the same image. I then wish to apply a CABasicAnimation to each CALayer in the array simultaneously by grouping via CATransactions. This all works one time. However, I would like to repeatedly call the block of CABasicAnimations that are contained in CATransactions but be able to modify the properties of each animation individually each time the block is executed simultaneously. For instance, I have from and to values for the animation that I would like to change randomly each time for the animation on each layer. Because I would like to repeat the same basic animation, but make property modification; setting repeatCount property of the animation to some high value will not work.I have tried calling the animate method repeatedly using a for loop within the makeSwarm method, using animationDidStop to induce another call of animate method but what ends up happening is a new call is made with the CATransaction block and not at the end , and also have the method call itself (put [self animate]; at the end of the animate method); and none of this works. Here is the basic code. I assume this is straightforward, but I am not seeing something important. Thanks, Seth

the ViewController.h

#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{
    UIImage *beeImage;

    UIImageView *beeView;
    CALayer *beeLayer;
    CABasicAnimation *animat;   
    NSMutableArray *beeArray;
    NSMutableArray *beeanimArray;

}

@property(retain,nonatomic) UIImage *beeImage;
@property(retain,nonatomic) NSMutableArray *beeArray;
@property(retain,nonatomic) NSMutableArray *beeanimArray;
@property(retain,nonatomic) UIImageView *beeView;
@property(retain,nonatomic) CALayer *beeLayer;
@property(retain,nonatomic)CABasicAnimation *animat;
-(void) animate;
-(void) makeSwarm;


@end

the ViewController.m

-(void) makeSwarm{

    self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
    self.view.layer.cornerRadius = 20.0;
    self.view.layer.frame = CGRectInset(self.view.layer.frame, 20, 20);

    CGRect beeFrame;
    beeArray = [[NSMutableArray alloc] init];
    beeImage = [UIImage imageNamed:@"bee50x55px.png"];
    beeFrame = CGRectMake(0, 0, beeImage.size.width, beeImage.size.height);


    int i;

    CALayer *p = [[CALayer alloc] init];


    for (i = 0; i < 3; i++) {



        beeView = [[UIImageView alloc] initWithFrame:beeFrame];
        beeView.image = beeImage;    
        beeLayer = [beeView layer];
        [beeArray addObject: beeLayer];  


        p = [beeArray objectAtIndex: i];    

        [p setPosition:CGPointMake(arc4random()%320, arc4random()%480)];
        [self.view.layer addSublayer:p];



    } 



    [self animate]; 

}

-(void)animate
{
    //the code from here to the end of this method is what I would like to repeat as many times as I would like
    [CATransaction begin];

    int i;
    for (i = 0; i < 3; i++) {  

        animat = [[CABasicAnimation alloc] init];
        [animat setFromValue:[NSValue valueWithCGPoint:CGPointMake(arc4random()%320, arc4random()%480)]];
        animat.toValue = [NSValue valueWithCGPoint:CGPointMake(arc4random()%320, arc4random()%480)];
        [animat setFillMode:kCAFillModeForwards];
        [animat setRemovedOnCompletion:NO];
        animat.duration=1.0;


        CALayer *p = [[CALayer alloc] init];
        p = [beeArray objectAtIndex: i]; 
        [p addAnimation:animat forKey:@"position"];



    }    

    [CATransaction commit];     


}
  • 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-02T06:45:06+00:00Added an answer on June 2, 2026 at 6:45 am

    I believe I have answered this for myself. I set the delegate for animation at the end of the loop (when i==2) and when that animation ends (indicating loop is over), then from the animationDidStop method I then call the method animate again. If there is a more elegant or trouble free solution than this, I’m all ears and will accept it as the answer.

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

Sidebar

Related Questions

I using a self compiled Obj-C Library in two of my iPhone Apps. Now,
I am using iPhone SDK 3.1.3. I have a UITableViewController which gets data from
I am working on iPhone app development currently (primarily native app using Obj-C and
I'm using the ASIHTTPRequest package to send some data from the iPhone to my
I'm trying to build an application in Android using some codes from Objective-C (IPhone
I don't have any idea how to post a JSON RPC request using Obj-C.
i am using this code to check if my glsl shader compiled fine. glGetObjectParameterivARB(obj,
I've been trying to make my own basic .obj (Wavefront) renderer using the OpenGL
I'm loading a JSON string in Django using simplejson , thus: obj = json.loads('{name:
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();

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.