Closed jolo2000 closed 12 years ago
Hi,
here is a small hack, which enables that feature. I added the following method to the PSBaseSubtree class:
(IBAction) toggleOneLevelExpansion:(id)sender
{
[UIView beginAnimations:@"TreeNodeExpansion" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
// optional: set the animation curve:
// UIViewAnimationCurveEaseIn: begins slowly, then speeds up
// UIViewAnimationCurveEaseOut: begins fast, then slows down
// UIViewAnimationCurveEaseInOut: begins slowly, faster in the middle, slows down at end
// UIViewAnimationCurveLinear: same speed throughout
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// optional: to execute code after the animation has finished, set the delegate:
[UIView setAnimationDelegate:self];
NSMutableArray ancestorsViews = [[NSMutableArray alloc]init];
UIView anAncestor = self;
PSBaseSubtreeView rootView;
while ([anAncestor isKindOfClass:[PSBaseSubtreeView class]] ) {
[ancestorsViews addObject:(PSBaseSubtreeView) anAncestor];
rootView = (PSBaseSubtreeView*) anAncestor;
anAncestor = [anAncestor superview];
}
// now we rebuild our path to the selected node
// get parent node
UIView selectedView = self;
for (UIView ancestor in ancestorsViews) {
NSArray childViews = [ancestor subviews];
for (UIView *childView in childViews) {
if ([childView isKindOfClass:[PSBaseSubtreeView class]]) {
// child view is a subtree
if ([(PSBaseSubtreeView)childView isEqual:(PSBaseSubtreeView) selectedView]) {
// toggle state
[(PSBaseSubtreeView)childView setExpanded:TRUE];
// show next sub level of the selected node/view and hide all sub-sub levels
if ([selectedView isEqual:self]) {
NSArray *subLevelViews = [childView subviews];
for (UIView *subLevelView in subLevelViews) {
if ([subLevelView isKindOfClass:[PSBaseSubtreeView class]]) {
[(PSBaseSubtreeView*)subLevelView setExpanded:FALSE];
}
if ([subLevelView isKindOfClass:[PSBaseLeafView class]]) {
[(PSBaseLeafView*)subLevelView setShowingSelected:FALSE];
}
}
}
selectedView = (PSBaseSubtreeView*) ancestor;
} else {
[(PSBaseSubtreeView*)childView setExpanded:FALSE]; // is o.k.
}
}
// handling of leaf views needed?
}
}
if ([rootView isKindOfClass:[PSBaseSubtreeView class]]) { [[rootView enclosingTreeGraph] setNeedsGraphLayout]; [[rootView enclosingTreeGraph] layoutGraphIfNeeded];
} else { NSLog(@"wrong root view class supplied: %@", [rootView description]); }
if ( [self modelNode] != nil ) { NSSet *visibleSet = [NSSet setWithObject:[self modelNode]]; [[self enclosingTreeGraph] scrollModelNodesToVisible:visibleSet animated:NO]; }
[UIView commitAnimations]; //NSLog(@"tree depth 1: %@", [self treeSummaryWithDepth:1]); [ancestorsViews release]; }
HTH Johannes
Hello,
i would like to start with a collapsed tree and with pressing the expand button, only the next layer of the subtree should be shown. Actually the whole subtree is displayed. Has anybody realized such a feature?
Yours Johannes