|
|
#1 |
|
Animating a CALayer sublayer
Hi.
I'm trying to animate the sublayer of a UIView's layer with the following code: Code:
CALayer *sublayer = [[CALayer alloc] init];
[sublayer setFrame:myRect]; // myRect is a portion of the view's frame rectangle
[self.layer addSublayer:sublayer];
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
anim.duration = 1.0f;
anim.fromValue = [NSNumber numberWithFloat:1];
anim.toValue = [NSNumber numberWithFloat:.5];
anim.delegate = self;
[sublayer addAnimation:anim forKey:@"animateOpacity"];
Code:
[self.layer addAnimation:anim forKey:@"animateOpacity"]; Thanks. |
|
|
|
0
|
|
|
#2 |
|
Memory leak at line 1. Use this instead unless your releasing it later on in your code.
CALayer *sublayer = [[[CALayer alloc] init] autorelease]; Is your sublayer visible? When it appears, does it appear at 1 or 0.5 opacity?
__________________
MacBook 4GBRam 320GBHDD iMac 20" 4GBRam 1TBHDD iPhone 16GB Cocoa Developer |
|
|
|
0
|
|
|
#3 | ||
|
Thanks for your reply.
Quote:
Quote:
Code:
[sublayer setHidden:FALSE]; [sublayer setNeedsDisplay]; |
|||
|
|
0
|
|
|
#4 |
|
How does your dealloc method have a reference to your sublayer? You've created it as a local variable.
__________________
|
|
|
|
0
|
|
|
#5 |
|
|
0
|
|
|
#6 |
|
And you're sure the sublayer's frame is set as needed?
__________________
|
|
|
|
0
|
|
|
#7 |
|
|
0
|
|
|
#8 |
|
It sound like the layer isn't actually added as a sublayer.
Do this: Code:
CALayer *parentLayer = self.layer; self.sublayer = [CALayer layer]; // proper way to set your member var - assuming the setter retains [sublayer setFrame:myRect]; [parentLayer addSublayer:sublayer]; // SET A BREAKPOINT HERE // ensure parentLayer is a valid CALayer // ensure sublayer.superlayer contains the address of parentLayer CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"]; anim.duration = 1.0f; anim.fromValue = [NSNumber numberWithFloat:1]; anim.toValue = [NSNumber numberWithFloat:.5]; anim.delegate = self; [sublayer addAnimation:anim forKey:@"animateOpacity"];
__________________
MacBook 4GBRam 320GBHDD iMac 20" 4GBRam 1TBHDD iPhone 16GB Cocoa Developer |
|
|
|
0
|
|
|
#9 |
|
I have just solved the problem: my sublayer wasn't visible because it wasn't initialized with any content. I added the line
Code:
sublayer.backgroundColor = [[UIColor redColor] CGColor]; |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| CALayer to pdf | MrFusion | Mac Programming | 1 | Aug 6, 2011 03:39 PM |
| Animation Desk for iPhone - Anyone can be an animator. Any idea matters. (New Video) | swopes | iPhone and iPod touch Apps | 4 | Jul 24, 2011 09:59 AM |
| zoom animation using animation with block based methods | ashwinr87 | iPhone/iPad Programming | 4 | Apr 20, 2011 09:24 AM |
| How does one make a UIImage Animation stop on an image. | nickculbertson | iPhone/iPad Programming | 3 | Nov 20, 2010 07:50 AM |
| How to write a jQuery animate in this situation? | youlichika | Web Design and Development | 1 | Nov 19, 2010 03:47 PM |
All times are GMT -5. The time now is 08:53 PM.







I support the
Linear Mode

