Changing frame inside of NSCollectionView

  • Hey all,

    I'm using NSCollectionView in a pet project of mine and I'm using it
    to create a list of items.  I've got the NSView drawing already
    complete but I'm having issues trying to resize it once it's in the
    Collection View.  Pretty much what I'm doing is this...I'm trying to
    keep it minimalistic, if the user selects an item it expands showing
    some extra optional information that was previously hidden.

    I've tried setting the frame with the following code...(which resides
    inside of the view I'm resizing)

    ...
    NSRect oldFrame = [self frame];
    NSRect newFrame = NSMakeRect( oldFrame.origin.x, oldFrame.origin.y,
    NSWidth(oldFrame), NSHeight(oldFrame) -100);

    [self setFrame: newFrame];

    [[self superview] setNeedsDisplay: YES];
    [self setNeedsDisplay: YES];
    ...

    I even added the [[self superview] setNeedsDisplay: YES] to try and
    get the superview to redisplay/recalculate position of objects.  I've
    tried enlarging the height and shrinking it and it still displays as
    the same thing on screen.

    Any ideas?

    Thanks,
    Tim
  • On $BJ?@.(B 19/11/09, at 7:52, Tim Davis wrote:

    > Hey all,
    >
    > I'm using NSCollectionView in a pet project of mine and I'm using it
    > to create a list of items.  I've got the NSView drawing already
    > complete but I'm having issues trying to resize it once it's in the
    > Collection View.  Pretty much what I'm doing is this...I'm trying to
    > keep it minimalistic, if the user selects an item it expands showing
    > some extra optional information that was previously hidden.
    >
    > I've tried setting the frame with the following code...(which
    > resides inside of the view I'm resizing)
    >
    > ...
    > NSRect oldFrame = [self frame];
    > NSRect newFrame = NSMakeRect( oldFrame.origin.x, oldFrame.origin.y,
    > NSWidth(oldFrame), NSHeight(oldFrame) -100);
    >
    > [self setFrame: newFrame];
    >
    > [[self superview] setNeedsDisplay: YES];
    > [self setNeedsDisplay: YES];
    > ...
    >
    > I even added the [[self superview] setNeedsDisplay: YES] to try and
    > get the superview to redisplay/recalculate position of objects.
    > I've tried enlarging the height and shrinking it and it still
    > displays as the same thing on screen.
    It won't really work, because NSCollectionView does not expose its
    layout mechanism.
    If it implemented - layoutSubviews (or layers) it could be overridden
    to support arbitrary layout...
    In this case, you can't really reliably AFAIK alter the sizes of items
    and "keep" thier size that way.... NSCOllectionView will put it back
    to the size it wants.

    So, in this case, I think you just have to do your own view, or have
    an accessory view that pops out like in iCal...

    Andre

    >
    > Any ideas?
    >
    > Thanks,
    > Tim
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today