Animating NSTabViewItem content change - how hard can it be?
Animating NSTabViewItem content change - how hard can it be?
- Subject: Animating NSTabViewItem content change - how hard can it be?
- From: Jokke Heikkila <email@hidden>
- Date: Mon, 10 Dec 2007 09:41:44 +0200
I'm on the look for some tips how to animate NSTabViewItem change but
so far haven't had any luck. I'm trying to have a such animation that
when user clicks a new tab in a tabView, the old tab contents slides
out of the view and at the same time the selected tabs content slide
in. I can get the animation of old tabViewItem slide out, but I can't
seem to be able to get the new tabViewItem to slide in at the same
time, its like the view stays somewhere behind and unvisible. Any
thoughts how this should be tackled? Below is NSTabView delegate that
I'm using to catch the action of new tab selection.
tia,
jokke h.
###
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:
(NSTabViewItem *)tabViewItem
{
// slide out animation
NSRect currentTabFrameStop;
NSMutableDictionary* currentTabDict;
NSView *currentTab = [[tabView selectedTabViewItem] view];
{
// Create the attributes dictionary for the current tab view
item.
currentTabDict = [NSMutableDictionary dictionaryWithCapacity:3];
// Specify which view to modify.
[currentTabDict setObject:currentTab
forKey:NSViewAnimationTargetKey];
NSLog(@"taking out item index: %d and view: %@", [tabView
indexOfTabViewItem:[tabView selectedTabViewItem]], currentTab);
// Specify the starting position of the view.
[currentTabDict setObject:[NSValue valueWithRect:[currentTab
frame]]
forKey:NSViewAnimationStartFrameKey];
// Change the ending position of the view.
currentTabFrameStop = [currentTab frame];
currentTabFrameStop.origin.x += currentTabFrameStop.size.width;
[currentTabDict setObject:[NSValue
valueWithRect:currentTabFrameStop]
forKey:NSViewAnimationEndFrameKey];
}
// slide in animation
NSRect nextTabFrameStart;
int indexOfSelectedTab = [tabView indexOfTabViewItem:tabViewItem];
NSMutableDictionary* nextTabDict;
NSView *selectedTabView = [[tabView
tabViewItemAtIndex:indexOfSelectedTab] view];
{
// Create the attributes dictionary for the next tab view item.
nextTabDict = [NSMutableDictionary dictionaryWithCapacity:3];
// Specify which view to modify.
[nextTabDict setObject:selectedTabView
forKey:NSViewAnimationTargetKey];
NSLog(@"sliding in item index: %d and view: %@", indexOfSelectedTab,
selectedTabView);
// Starting position of the view.
nextTabFrameStart = [selectedTabView frame];
nextTabFrameStart.origin.x -= nextTabFrameStart.size.width;
[nextTabDict setObject:[NSValue valueWithRect:nextTabFrameStart]
forKey:NSViewAnimationStartFrameKey];
// Specify the ending position of the view.
[nextTabDict setObject:[NSValue valueWithRect:[selectedTabView
frame]]
forKey:NSViewAnimationEndFrameKey];
}
// Create the view animation object.
NSViewAnimation *theAnim = [[NSViewAnimation alloc]
initWithViewAnimations:[NSArray
arrayWithObjects:currentTabDict, nextTabDict, nil]];
// Set some additional attributes for the animation.
[theAnim setDuration:1.4];
[theAnim setAnimationCurve:NSAnimationEaseIn];
[theAnim setAnimationBlockingMode:NSAnimationBlocking];
[theAnim startAnimation];.
[theAnim release];
}
_______________________________________________
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