• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Animating NSSplitPane position
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Animating NSSplitPane position


  • Subject: Re: Animating NSSplitPane position
  • From: Graham Cox <email@hidden>
  • Date: Thu, 16 Jun 2011 16:40:49 +1000

Hi Antonio, wow - that's a substantial response! Thanks!


I did find a simple way to do it which suits my needs, though it's not perfect. I added a category on NSSplitView (not pane - my bad) as follows:

@implementation NSSplitView (Animation)


+ (id)	defaultAnimationForKey:(NSString *)key
{
    if ([key isEqualToString:@"splitPosition"])
    {
        CAAnimation* anim = [CABasicAnimation animation];

	anim.duration = 0.3;

	return anim;
    }
    else
    {
        return [super defaultAnimationForKey:key];
    }
}


- (void)		setSplitPosition:(CGFloat) position
{
	[self setPosition:position ofDividerAtIndex:0];
}


- (CGFloat)		splitPosition
{
	NSRect frame = [[[self subviews] objectAtIndex:0] frame];

	if([self isVertical])
		return NSMaxX( frame );
	else
		return NSMaxY( frame );
}

@end


This allows my new property 'splitPosition' to be animatable by the animator. Its main drawback is that because it calls through to setPosition:ofDividerAtIndex:, it will snap shut when it reaches the appropriate threshold. For me that's OK as my minimum position is quite small,  but I guess you could, as you did, tell the delegate that animation is happening so that it temporarily changes the threshold so that it doesn't snap. It also assumes that there's only a single split, as it hard-codes index 0. Used like this:

[[mySplitView animator] setSplitPosition:<whatever>];



--Graham





On 16/06/2011, at 4:05 PM, Antonio Nunes wrote:

> On 16 Jun 2011, at 03:48, Graham Cox wrote:
>
>> I'm using -setPosition:ofDividerAtIndex: and I call this using the view's animator:
>>
>> 	[[mySplitPane animator] setPosition:position ofDividerAtIndex:0];
>>
>> But it doesn't animate and just jumps into position. I see other apps manage this (e.g. Mail) so how's it done?
>
> Hi Graham,
>
> Having recently experienced the same limitation, I found we need to manually resize the subviews (through their animator). I posted a message here, on June 1st, titled "Animated Split View", in which I exposed a solution and asked for feedback on it (got none). Meanwhile I have improved the code, since I found the first iteration not to be robust enough. The new version follows:
>
> ==========
> @interface NSSplitView (NSSplitView_Animation)
>
> - (CGFloat)catPositionOfDividerAtIndex:(NSInteger)index;
> - (void)catAnimateDividerIndexes:(NSArray *)indexes toPositions:(NSArray *)newPositions;
> - (void)catAnimateDividerAtIndex:(NSInteger)index toPosition:(CGFloat)newPosition;
>
> @end
[]

_______________________________________________

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

References: 
 >Animating NSSplitPane position (From: Graham Cox <email@hidden>)
 >Re: Animating NSSplitPane position (From: Antonio Nunes <email@hidden>)

  • Prev by Date: Re: Animating NSSplitPane position
  • Next by Date: Re: Custom NSSlider
  • Previous by thread: Re: Animating NSSplitPane position
  • Next by thread: Hiding/Showing UIAgent application window
  • Index(es):
    • Date
    • Thread