Re: Flip and Enlarge CALayer at the same time
Re: Flip and Enlarge CALayer at the same time
- Subject: Re: Flip and Enlarge CALayer at the same time
- From: Gustavo Pizano <email@hidden>
- Date: Tue, 22 Jun 2010 16:13:52 +0200
HEllo all... I had an advance
:) :) :)
so I did this - (void) setFaceUp: (BOOL)up
{
if( up != _faceUp ) {
// The Card has separate sub-layers for its front and back. At any time, one of them
// is hidden, by having a 180 degree rotation about the Y axis.
// To flip the card, both front and back layers are flipped over.
CATransform3D xform;
xform = up ?kFaceUpTransform :kFaceDownTransform;
CABasicAnimation * flipAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
flipAnim.toValue = [NSValue valueWithCATransform3D:xform];
flipAnim.duration = 0.5f;
flipAnim.cumulative = NO;
flipAnim.removedOnCompletion = NO;
flipAnim.autoreverses = NO;
flipAnim.fillMode = kCAFillModeForwards;
//_front.transform = xform;
[_front addAnimation:flipAnim forKey:@"flipAnimFront"];
[self performSelector:@selector(enlargeCALayer) withObject:nil afterDelay:0.29];
xform = up ?kFaceDownTransform :kFaceUpTransform;
flipAnim.toValue = [NSValue valueWithCATransform3D:xform];
//_back.transform = xform;
[_back addAnimation:flipAnim forKey:@"flipAnimBack"];
_faceUp = up;
}
}
- (void)enlargeCALayer{
CABasicAnimation * frameAnim = [CABasicAnimation animationWithKeyPath:@"position"];
[frameAnim setFromValue:[NSValue valueWithPoint:self.position]];
NSRect r = [self superlayer].bounds;
NSPoint p = NSMakePoint((r.origin.x + r.size.width)/2.0f, (r.origin.y + r.size.height)/2.0f);
[frameAnim setToValue:[NSValue valueWithPoint:p]];
frameAnim.cumulative= NO;
frameAnim.removedOnCompletion=NO;
frameAnim.autoreverses = NO;
frameAnim.fillMode=kCAFillModeForwards;
[self addAnimation:frameAnim forKey:nil];
}
plaese correct to make it better, I know it can be done better way, right now its not scaling but its repositioning the layer to the middle point of its superview :)
so know im missing the scaling while repositioning.
any suggestions?
Gustavo
On Jun 22, 2010, at 3:36 PM, Gustavo Pizano wrote:
> Hello, Im trying to recreate a flip-n-scale of a CALayer, pretty much the same as in iPhoto when you click the info of a event, it will flipt and enlarge a layer, but the back side of the layer its another view.
> So this is what I have so far base on the GameGeek board game example from apple.
>
> - (void) setFaceUp: (BOOL)up
> {
> if( up != _faceUp ) {
> // The Card has separate sub-layers for its front and back. At any time, one of them
> // is hidden, by having a 180 degree rotation about the Y axis.
> // To flip the card, both front and back layers are flipped over.
> CATransform3D xform;
> xform = up ?kFaceUpTransform :kFaceDownTransform;
> CABasicAnimation * flipAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
>
> flipAnim.toValue = [NSValue valueWithCATransform3D:xform];
> flipAnim.duration = 0.5f;
> flipAnim.cumulative = NO;
> flipAnim.removedOnCompletion = NO;
> flipAnim.autoreverses = NO;
> flipAnim.fillMode = kCAFillModeForwards;
> //_front.transform = xform;
> [_front addAnimation:flipAnim forKey:@"flipAnimFront"];
> xform = up ?kFaceDownTransform :kFaceUpTransform;
> flipAnim.toValue = [NSValue valueWithCATransform3D:xform];
> //_back.transform = xform;
> [_back addAnimation:flipAnim forKey:@"flipAnimBack"];
> _faceUp = up;
> }
> }
>
> when I click my info button the layer its flipped correctly and at the end I end up p whit the front CALayer being shown.
> I was trying then to add the "scaling" animation by adding a CAKeyAnimation with the values and times, then add the flipAnimation and the keyAnimation into a group and add it to the layer...but unfortunately id doesn't work. I see it flipped and once flips one face of the layer then it display nothing.
>
> My guesses..:
>
> I have this structure: CALayer with 2 CALayers ivars, (_front and _back), so right now its working the flipping from _front to back, so I guess this is not working because Im not setting the frame animation to the parent layer, which at the end its the one it should resize.
>
> Im sorry Im kinda confused here, so any help will be gladly appreciate it.
>
> thx
>
> Gustavo
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden