What's wrong with NSViewAnimation and view with zero height or width ?
What's wrong with NSViewAnimation and view with zero height or width ?
- Subject: What's wrong with NSViewAnimation and view with zero height or width ?
- From: Eric Morand <email@hidden>
- Date: Tue, 21 Mar 2006 15:24:47 +0100
Hi list !
I'm encountering a strange problem with NSViewAnimation.
Here is what i'm trying to do :
I have an NSImageView that I want to make disappear/reappear when
clicking on a button.
Here is the method attached to the button :
- (IBAction)testButton:(id)sender
{
NSRect viewStartFrame = [imageView frame];
NSRect viewEndFrame = NSZeroRect;
if ( viewStartFrame.size.height == 0.0 )
{
NSLog (@"here");
viewEndFrame.origin.x = 100.0;
viewEndFrame.origin.y = 100.0;
viewEndFrame.size.width = 500.0;
viewEndFrame.size.height = 500.0;
}
// ...
NSViewAnimation * theAnimation = nil;
NSMutableDictionary * theDict = [NSMutableDictionary
dictionaryWithCapacity:3];
NSMutableArray * animationsArray = [NSMutableArray array];
[theDict setObject:imageView forKey:NSViewAnimationTargetKey];
[theDict setObject:[NSValue valueWithBytes:&viewStartFrame
objCType:@encode(NSRect)] forKey:NSViewAnimationStartFrameKey];
[theDict setObject:[NSValue valueWithBytes:&viewEndFrame
objCType:@encode(NSRect)] forKey:NSViewAnimationEndFrameKey];
[animationsArray addObject:theDict];
theAnimation = [[NSViewAnimation alloc]
initWithViewAnimations:animationsArray];
[theAnimation setDuration:0.5];
[theAnimation startAnimation];
}
Everything works perfectly when I click on the button the first time
(the image view shrinks until it disappears). Than, when I ckick once
again on the button, the "here" log appears on the console
but...nothing happens ! The animation runs but the image view never
reappears.
I've then tried this :
- (IBAction)testButton:(id)sender
{
NSRect viewStartFrame = [imageView frame];
NSRect viewEndFrame = NSZeroRect;
if ( viewStartFrame.size.height == 1.0 )
{
NSLog (@"here");
viewEndFrame.origin.x = 0.0;
viewEndFrame.origin.y = 0.0;
viewEndFrame.size.width = 500.0;
viewEndFrame.size.height = 500.0;
}
else
{
viewEndFrame.size.width = 1.0;
viewEndFrame.size.height = 1.0;
}
// ...
NSViewAnimation * theAnimation = nil;
NSMutableDictionary * theDict = [NSMutableDictionary
dictionaryWithCapacity:3];
NSMutableArray * animationsArray = [NSMutableArray array];
[theDict setObject:imageView forKey:NSViewAnimationTargetKey];
[theDict setObject:[NSValue valueWithBytes:&viewStartFrame
objCType:@encode(NSRect)] forKey:NSViewAnimationStartFrameKey];
[theDict setObject:[NSValue valueWithBytes:&viewEndFrame
objCType:@encode(NSRect)] forKey:NSViewAnimationEndFrameKey];
[animationsArray addObject:theDict];
theAnimation = [[NSViewAnimation alloc]
initWithViewAnimations:animationsArray];
[theAnimation setDuration:0.5];
[theAnimation startAnimation];
}
And it works !
Can someone explain me why my view doesn't reappear if I set its
height (or width) to zero ?
I'm certainly doing something wrong but I can't see why and I'm stuck
with this problem since 4 hours now.
Any help appreciated,
Eric.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden