Design issue: Core Animation, NSCollectionView and NSCollectionViewItems

I am struggling with a design issue: I have an NSCollectionView that contains several items (it's binded to an NSArrayController which is, in turn, binded to a NSManagedObjectContext). I have decided to draw the view for each single item programmatically, mainly because I noticed that nesting several NSViews inside the Item View creates performance issues when there are more than a certain number of items in the collection view.
Consider the following hierarchy: NSCollectionView => NSCollectionViewItem -> NSView. (The default one used by NSCollectionView). My custom NSView contains several layers, some are CATextLayers, others are regular CALayers, and they all animate together (within the same CATransaction) whenever they need to. The issue here is that each CALayer needs to display the content of some data which is accessible through the representedObject property of the NSCollectionViewItem... which owns the NSView! I have two options (probably many more, I'm more than open to suggestions):
- I replicate the representedObject from the NSCollectionViewItem to its NSView, and I keep it consistent througout the execution of the program. I don't really like this one.
- I expose the CALayers in the NSView, and I set their content/string from within the NSCollectionViewItem's setRepresentedObject: method. I like this one better, because there is no data saved in the NSView (except for that which is being shown by through the layers, of course).
Am I wrong? Is there a more elegant solution?

Thanks in advance, I really apreciate the help. Cheers

Gian Marco

-------------Problems Reply------------

Came across this question quite late, and I thought it was an interesting design problem.

In case you haven't cracked this one or didn't like either of your solutions:

I would suggest writing an NSCollectionViewItem subclass that observes the self.representedObject key path(s), and refreshes its view and subviews when the model object changes.

NSCollectionViewItem is an NSViewController, which implies it should be responsible for managing its views. You can respect that by having the view layer that it works with, as a user-facing representation of its model object, held in its representedObject property. So, by watching all the necessary properties of the model using KVO, you should have a neat place to invoke all the view operations concerning 'rendering' the model. You should have full control at this funnel on whether you would like to work with the NSView API or the CALayer API.

Based on how complicated your prototype item view is, the size and volatility of the item set, the 'liveliness' requirement of the UI, and other factors, you might be able to get away with a very coarse-grain observation of the model, or need a very fine-grained one - I hope you got used to working with the KVO API!

I'm keen to also hear what choice you made in the end.

Category:objective c Views:1 Time:2011-11-24

Related post

  • Core Plot:Memory Issue Core animation failed to allocate so many bytes 2012-04-09

    I am using core plot for generation various types of graphs using webservices.But after generating around 60 graphs the graph scren appears to be blank giving a message in the device log as "Core animation failed to allocate 9997432 bytes" we are fac

  • How to get better at UIKit/Core Animation with no design experience? 2011-01-22

    I've read through Aaron Hillegass's iPhone Programming: The Big Nerd Ranch Guide and I feel I have a solid understanding on the fundamental design patterns/APIs of UIKit. After searching on both here and on Google, it seems that to take the 'next ste

  • AVFoundation Issue With Core Animation on Mac OS X 10.7 Lion 2011-09-23

    With Mac OS X 10.7 Apple has introduced AVFoundation and I'm trying to generate a simple quick time movie containing an animated shape. The problem is that the core animation does not render and I end-up having only a blank "black" video. Below is th

  • iOS Core-Animation: Performance issues with CATransaction / Interpolating transform matrices 2011-02-15

    I am performance testing my iPhone app: // using CATransaction like this goes from 14fps to 19fps [CATransaction begin]; [CATransaction setDisableActions: YES]; // NEG, as coord system is flipped/messed up self.transform = CGAffineTransformMakeRotati

  • Issue rotating a UIView object using Core Animation and blocks 2011-08-30

    I have a problem with a UIView-subclass object that I am rotating using Core Animation in response to a UISwipeGesture. To describe the context: I have a round dial that I have drawn in CG and added to the main view as a subview. In response to swipe

  • Blinking a UILabel issue using core animation 2012-04-16

    I would like to have a text that blink using core animation. I have put the following code but I don't see the text neither see it blinking. // Create a blinking text UILabel* labelText = [[UILabel alloc] initWithFrame:CGRectMake(355, 490, 400, 50)];

  • How do I prevent Core Animation blocking my main thread? 2009-02-27

    I'm aware of the fact that Core Animation dispatches its animations in a seperate thread, as stated in the documentation. Nevertheless, my animations seem to be blocking my main thread. All animations start and finnish. (With or without kCATransactio

  • iOS / Core-Animation: Performance tuning 2011-02-15

    I have my app running on my iPad. but it is performing very badly -- I am getting below 15fps. can anyone help me to optimise? It is basically a wheel (derived from UIView) containing 12 buttons (derived from UIControl). As the user spins it, the but

  • GUI design issues using C++ , Qt on Windows (Vista) 2012-03-14

    This concerns C++ (MinGW), Qt, Windows Vista: all this while i's developing non-GUI applications in C++. Recently i decided to try a GUI one in Qt and am having some design issues. Here's the problem: step 1: Load and display a background gif Animati

  • How can I use Core Animation to interpolate property values over time on my own classes? 2008-09-06

    Specifically, I am looking to use CA on properties of types other than integers and doubles CGRect, CGPoint, CGSize, and CGAffineTransform structures CATransform3D data structures CGColor and CGImage references and in objects other than CALayers or N

  • Image sequence animation with Core Animation 2008-11-03

    I'm currently using a UIImageView with an array of images to create a small looping animation sequence with about 20 images in there (at 320x480). Whilst this works okay for 20 - 30 images, any more and the app quits on the iphone. There is nothing e

  • Can Ruby really have design issues that the design patterns solve? 2009-01-27

    I recently started digging into design patterns. Generally speaking, I thought the design issues that most of the design patterns solve do not generally occur in Ruby. Most of the design issues were because of datatypes (No dynamic typing and arrays

  • Is there a way to find out if an application uses Core Animation or OpenGL ES? 2009-06-03

    I'm very interested in the technology behind ConvertBot. I tried to do a lot of stuff with Core Animation, but what I am seeing there looks just too fast for Core Animation. I tried to open it with Instruments, but it doesn't work with 3rd-party apps

  • Jerky/juttery (core-)animation in a screensaver? 2009-06-17

    I've built a screensaver for Leopard which utilises core-animation. It doesn't do anything overly complicated; uses a tree of CALayers and CATextLayers to produce a "table" of data in the following structure: - root › maincontainer › subcontainer › r

  • Does openGL ES have a better performance than Core Animation and UIKit when it comes to highly animated user interfaces? 2009-07-16

    Currently I have an user interface that makes incredible heavy use of core animation. I wonder if it is worth to spent another 2 months for learning openGL ES? Does that really improve drawing performance for 2D surfaces? I have no 3D objects, but hi

  • Using Core Animation/CALayer for simple layered painting 2009-07-30

    I would like to create a custom NSView that takes a layered approach to painting. I imagine the majority of the layers would be the same width and height as the backing view. Is it appropriate to use the Core Animation classes like CALayer for this t

  • Residual/trace in Core Animation & CALayers 2009-12-10

    I am making an Cocoa app, using Core Animation to create custom UI. However, whenever I drag some layers around, they often leave some "residuals/traces" onto the other layers. So far, my guess is that it is related to my usage of [setNeedsDisplay].

  • Can Core Animations supports a 20 frames per second enlargement from 32 x 32 px to 120 x 170 px? 2009-12-15

    my background.jpg has 52 32x32 mini poker cards.png and when user touch on 1 card, it will enlarge to 120x 170 px. At any point in time, there is only 1 card being chosen (i.e, being animated) with at most 19 entire cards overlapped (120x170 / 32x32)

  • Multiple inheritance design issue in Java 2010-01-26

    How do you deal with having only single inheritance in java? Here is my specific problem: I have three (simplified) classes: public abstract class AbstractWord{ String kind; // eg noun, verb, etc public String getKind(){ return kind; } } public class

Copyright (C), All Rights Reserved.

processed in 0.111 (s). 11 q(s)