Re: CALayer: Animation using actions property

2011-04-22 Thread Bhatnagar, Arvin
Yeah I am using GC. I will test out the GCC compiler, thanks for the direction.

FYI: Using an NSTimer for animation increases CPU % utilization more so than 
adding the animation in the layer and letting it run.


From: David Duncan david.dun...@apple.commailto:david.dun...@apple.com
Date: Thu, 21 Apr 2011 12:03:50 -0400
To: Arvin Bhatnagar 
arvin.bhatna...@one.verizon.commailto:arvin.bhatna...@one.verizon.com
Cc: cocoa-dev cocoa-dev@lists.apple.commailto:cocoa-dev@lists.apple.com
Subject: Re: CALayer: Animation using actions property

On Apr 20, 2011, at 8:07 AM, Bhatnagar, Arvin wrote:

The code below, when compiled w/ Xcode 3.2 does not display the layer…but, with 
Xcode 4 it works just fine?

I have no idea why this is the case.

I'm not certain what would cause this unfortunately. The only possibility I can 
think of is that you are using different compilers that are optimizing 
differently *and* that you are using Garbage Collection (which you allude to 
when you set various values to nil). But if you aren't using GC, then I have no 
idea (and setting the values to nil has no effect either).
--
David Duncan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CALayer: Animation using actions property

2011-04-21 Thread David Duncan
On Apr 20, 2011, at 8:07 AM, Bhatnagar, Arvin wrote:

 The code below, when compiled w/ Xcode 3.2 does not display the layer…but, 
 with Xcode 4 it works just fine?
 
 I have no idea why this is the case.


I'm not certain what would cause this unfortunately. The only possibility I can 
think of is that you are using different compilers that are optimizing 
differently *and* that you are using Garbage Collection (which you allude to 
when you set various values to nil). But if you aren't using GC, then I have no 
idea (and setting the values to nil has no effect either).
--
David Duncan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CALayer: Animation using actions property

2011-04-20 Thread Bhatnagar, Arvin
David ­ Thank you for the direction, I am no longer using a timer for this
Animation.

However the code below, when compiled w/ Xcode 3.2 does not display the
dot layersŠbut,
with Xcode 4 it works just fine?

I have no idea why this is the case. Is it a bug?



Not too complex:

- (void) _createDotLayer {
 
CGFloat radius  = 2.0f;
CGFloat startTime   = 0.05f * _noOfDots;

[self _removeDotLayers];
mDotLayers = [[NSMutableArray alloc] initWithCapacity:_noOfDots];

NSUInteger i, offset;
for ( i=0; i  _noOfDots; i++ ) {

CALayer* dotLayer = [CALayer layer];

// Array of Constraints
offset += 10;
NSArray* dotConstraints = [NSArray arrayWithObjects:[CAConstraint
constraintWithAttribute:kCAConstraintMinX
   
relativeTo:@mmText
   
 attribute:kCAConstraintMaxX
   
 scale:1.0f
   
offset:offset],
[CAConstraint
constraintWithAttribute:kCAConstraintMinY
   
relativeTo:@mmText
   
 attribute:kCAConstraintMinY
   
 scale:1.0f
   
offset:3], nil];
// Dot Layer Properties
dotLayer.backgroundColor=
CGColorGetConstantColor(kCGColorWhite);
dotLayer.cornerRadius   = radius;
dotLayer.frame  =
CGRectMake(0.0f,0.0f,radius*2,radius*2);
dotLayer.constraints= dotConstraints;
dotLayer.opacity= 0.0f;

// Dot Layer Animation
CABasicAnimation* forward = [CABasicAnimation animation];
[forward setFromValue:[NSNumber numberWithFloat:0.0f]];
[forward setToValue:[NSNumber numberWithFloat:1.0f]];
[forward setKeyPath:@opacity];
[forward setAutoreverses:NO];
[forward setFillMode:kCAFillModeForwards];
[forward setBeginTime:(i * startTime)];

CABasicAnimation* backward = [CABasicAnimation animation];
[backward setFromValue:[NSNumber numberWithFloat:1.0f]];
[backward setToValue:[NSNumber numberWithFloat:0.0f]];
[backward setKeyPath:@opacity];
[backward setAutoreverses:NO];
[backward setFillMode:kCAFillModeForwards];
[backward setBeginTime:((i * startTime) * 2)];

// Dot Layer Group Animation
CAAnimationGroup* groupAnimation = [CAAnimationGroup animation];
[groupAnimation setAnimations:[NSArray arrayWithObjects:forward,
backward, nil]];
[groupAnimation setDuration:_noOfDots];
[groupAnimation setRemovedOnCompletion:NO];
[groupAnimation setAutoreverses:NO];
[groupAnimation setRepeatCount:HUGE_VALF];
[groupAnimation setFillMode:kCAFillModeBoth];

[dotLayer addAnimation:groupAnimation forKey:@dotAnimations];

// Add Dot Layer to Loading Layer
[self addSublayer:dotLayer];
[mDotLayers addObject:dotLayer];

// Garbage Collect
forward = nil;
backward= nil;
groupAnimation  = nil;
dotConstraints  = nil;
}
}


Thanks,
Arvin

From:  David Duncan david.dun...@apple.com
Date:  Tue, 19 Apr 2011 12:31:58 -0400
To:  Arvin Bhatnagar arvin.bhatna...@one.verizon.com
Cc:  cocoa-dev cocoa-dev@lists.apple.com
Subject:  Re: CALayer: Animation using actions property



On Apr 19, 2011, at 9:26 AM, Bhatnagar, Arvin wrote:


Ok that worked if I were animating just one layer on its own. However, I
am animating three separate layers in sequence to one another. I know we
can group multiple animations for one layer (CAGroupAnimation). Other than
using a timer, is there an alternative to coordinating the animation of
different layers?




All you should need to do is add the appropriate animations to each layer.
If you need some kind of delay between them, you may find that putting
them in a group animation gives you a nested context to do so. For example
if you want an animation that progresses forward, pauses then reverses it
may make more sense to have a group animation with 2 animations on a
timeline with the included delays that repeats (but doesn't autoreverse,
since your doing the reversal yourself).
Depending on how you feel about it, it can either be a complex or fun game
to see what you can do with animations to get an effect by itself )
--
David Duncan







___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CALayer: Animation using actions property

2011-04-19 Thread Bhatnagar, Arvin
I fixed my own issue.

It has to do with the timer. In short when using a timer to animate a
layer I was using scheduledTimerWithTimeInterval versus
timerWithTimeInterval. When I use timerWithTimeInterval I then set the
Fire Date and add the timer to three modes: (NSRunLoopCommonModes,
NSDefaultRunLoopMode, NSEventTrackingRunLoopMode). Now when I resize my
view the timer doesn't stall and the animation continues.

This worked for me, and I can only assume that adding the timer to these
other two modes was the solution: NSRunLoopCommonModes /
NSEventTrackingRunLoopMode.

If anybody can explain this further, I am all ears!

Thanks,
Arvin


On 4/18/11 10:49 PM, Bhatnagar, Arvin arvin.bhatna...@verizon.com
wrote:

Hi All,

This is probably a simple question for someone other than I.

I have a very simple CALayer which is a simple plain layer with a white
background. I then create a CABasicAnimation and add it to the actions
property to animate the @opacity. From here I setup a timer to fire and
toggle the opacity between 0 and 1 which animates.

My issue is, when I go to resize the window the animation halts. Anybody
know why this occurs and if I can allow the animation to continue even if
I resize the view that the layer resides in? It's probably something
small and simple, but just don't know what it is and can't find it in the
documentation.

Oh yeah, my later tree is setup as such:

[CALayer rootLayer]
[view setWantsLayers:YES]
[[view layer] addSublayer:mBasicLayer]

Thanks,
Arvin
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/arvin.bhatnagar%40verizon
.com

This email sent to arvin.bhatna...@verizon.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CALayer: Animation using actions property

2011-04-19 Thread David Duncan
On Apr 18, 2011, at 7:49 PM, Bhatnagar, Arvin wrote:

 This is probably a simple question for someone other than I.
 
 I have a very simple CALayer which is a simple plain layer with a white 
 background. I then create a CABasicAnimation and add it to the actions 
 property to animate the @opacity. From here I setup a timer to fire and 
 toggle the opacity between 0 and 1 which animates.


Your analysis of the timer was correct, but I wanted to talk to this point 
instead – rather than using a timer to toggle the opacity, you could just add 
an animation to the layer that auto-reverses and repeats indefinitely, which 
would likely give you the same effect without having to run a timer at all.
--
David Duncan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CALayer: Animation using actions property

2011-04-19 Thread Bhatnagar, Arvin
Thanks David, I am going to try that suggestion right now.

On 4/19/11 11:59 AM, David Duncan david.dun...@apple.com wrote:

On Apr 18, 2011, at 7:49 PM, Bhatnagar, Arvin wrote:

 This is probably a simple question for someone other than I.
 
 I have a very simple CALayer which is a simple plain layer with a white
background. I then create a CABasicAnimation and add it to the actions
property to animate the @opacity. From here I setup a timer to fire
and toggle the opacity between 0 and 1 which animates.


Your analysis of the timer was correct, but I wanted to talk to this
point instead ­ rather than using a timer to toggle the opacity, you
could just add an animation to the layer that auto-reverses and repeats
indefinitely, which would likely give you the same effect without having
to run a timer at all.
--
David Duncan


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CALayer: Animation using actions property

2011-04-19 Thread Bhatnagar, Arvin
Ok that worked if I were animating just one layer on its own. However, I am 
animating three separate layers in sequence to one another. I know we can group 
multiple animations for one layer (CAGroupAnimation). Other than using a timer, 
is there an alternative to coordinating the animation of different layers?

Some Code:

- (void) moveDots {



// Animate Dot Opacity

CALayer* dot = (CALayer *)[mDotLayers objectAtIndex:mDotPosition];

dot.opacity = mDotDirection ? 0.0f : 1.0f;

[self setNeedsDisplay];



// NO -- Forward, YES -- Backward

if ( !mDotDirection ) mDotPosition++;

if (  mDotDirection ) mDotPosition--;



if ( mDotPosition  0 ) {

mDotPosition = 0;

mDotDirection = NO;

}



if ( mDotPosition  (_noOfDots-1) ) {

mDotPosition = (_noOfDots-1);

mDotDirection = YES;

}

}


- (void) _startAnimationTimer {


// Just in case

[self _stopAnimationTimer];



// Dot Layer Timer

mDotTimer = [NSTimer timerWithTimeInterval:(NSTimeInterval)1.0f

target:self

  selector:@selector(moveDots)

  userInfo:nil

   repeats:YES];

[mDotTimer setFireDate:[NSDate date]];

[[NSRunLoop currentRunLoop] addTimer:mDotTimer 
forMode:NSRunLoopCommonModes];

[[NSRunLoop currentRunLoop] addTimer:mDotTimer 
forMode:NSDefaultRunLoopMode];

[[NSRunLoop currentRunLoop] addTimer:mDotTimer 
forMode:NSEventTrackingRunLoopMode];

}


Thanks,

Arvin

On 4/19/11 12:07 PM, Bhatnagar, Arvin 
arvin.bhatna...@verizon.commailto:arvin.bhatna...@verizon.com wrote:

Thanks David, I am going to try that suggestion right now.

On 4/19/11 11:59 AM, David Duncan 
david.dun...@apple.commailto:david.dun...@apple.com wrote:

On Apr 18, 2011, at 7:49 PM, Bhatnagar, Arvin wrote:

This is probably a simple question for someone other than I.
I have a very simple CALayer which is a simple plain layer with a white
background. I then create a CABasicAnimation and add it to the actions
property to animate the @opacity. From here I setup a timer to fire
and toggle the opacity between 0 and 1 which animates.


Your analysis of the timer was correct, but I wanted to talk to this
point instead ­ rather than using a timer to toggle the opacity, you
could just add an animation to the layer that auto-reverses and repeats
indefinitely, which would likely give you the same effect without having
to run a timer at all.
--
David Duncan


___

Cocoa-dev mailing list 
(Cocoa-dev@lists.apple.commailto:Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/arvin.bhatnagar%40verizon.com

This email sent to 
arvin.bhatna...@verizon.commailto:arvin.bhatna...@verizon.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CALayer: Animation using actions property

2011-04-19 Thread David Duncan

On Apr 19, 2011, at 9:26 AM, Bhatnagar, Arvin wrote:

 Ok that worked if I were animating just one layer on its own. However, I am 
 animating three separate layers in sequence to one another. I know we can 
 group multiple animations for one layer (CAGroupAnimation). Other than using 
 a timer, is there an alternative to coordinating the animation of different 
 layers?


All you should need to do is add the appropriate animations to each layer. If 
you need some kind of delay between them, you may find that putting them in a 
group animation gives you a nested context to do so. For example if you want an 
animation that progresses forward, pauses then reverses it may make more sense 
to have a group animation with 2 animations on a timeline with the included 
delays that repeats (but doesn't autoreverse, since your doing the reversal 
yourself).

Depending on how you feel about it, it can either be a complex or fun game to 
see what you can do with animations to get an effect by itself )
--
David Duncan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com