• 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: Layers in NSCollectionView (solved)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Layers in NSCollectionView (solved)


  • Subject: Re: Layers in NSCollectionView (solved)
  • From: Gordon Apple <email@hidden>
  • Date: Sat, 08 Dec 2012 10:36:33 -0600
  • Thread-topic: Layers in NSCollectionView (solved)

Some things turn out to be simple, if you know where to look.  I¹m posting
this in case anyone else runs into this issue.  Unfortunately, the
Collection View Guide does not mention it.  The solution is to subclass
NSCollectionView and override newItemForRepresentedObject.  It gives you the
representedObject for each cell.  You don¹t even need a prototype and can
supply any view you want for the cell.  In this case, the form for each cell
is the same, so you can just copy the prototype, then customize it as
needed.  You just have to have a way to find the subviews you want to
customize.  Here is my code:

#import "RTPAVControlCollectionView.h"
#import "RTPAVMovieView.h"

@implementation RTPAVControlCollectionView

- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
    // Get a copy of the item prototype, set represented object
    NSCollectionViewItem *newItem = [[self itemPrototype] copy];
    [newItem setRepresentedObject:object];

    // Get the new item's view¹s subviews.
    NSView *itemView = [newItem view];
    NSArray *subViews = itemView.subviews;

    //  Find subview to customize.  //  Type, tag, whatever.
    RTPAVMovieView *movieView;
    for(NSView *view in subViews)
        if([view isKindOfClass:[RTPAVMovieView class]]) {
            movieView = (RTPAVMovieView*)view;
            break;
        }

    //  Customize.
    if(movieView != nil)
        [movieView addPlayerLayerForPlayer:object]; //  RepresentedObject is
our subclass of AVPlayer.

    return newItem;
}

For the movie view, add the AVPlayerLayer (or at least the AVPlayer) in
addPlayerLayerForPlayer:, NOT in awakeFromNib, because the view has already
been set up.  Works great.  Now I have playing thumbnails in my popover
collection view, each with controls for the movies in the main screen.  Now,
you can see what you are controlling in the popover.


On 12/4/12 11:17 AM, "Gordon Apple" <email@hidden> wrote:

> This collection  is a bank of AVPlayer controls for all movies which currently
> appear in the presentation window, on a different screen, and I want a
> (hopefully) playing thumbnail by the controls for easy identification.  I may
> have to settle for a starting image, which isn¹t very useful is the movies
> fade in from black.  Another thing AVFoundation lacks is access to something
> like a poster frame.


_______________________________________________

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: 
 >Re: Layers in NSCollectionView (From: Gordon Apple <email@hidden>)

  • Prev by Date: Re: How to implement readonly property
  • Next by Date: Re: delaying document close
  • Previous by thread: Re: Layers in NSCollectionView
  • Next by thread: Re: Cocoa-dev Digest, Vol 9, Issue 823
  • Index(es):
    • Date
    • Thread