I am trying to create a grid style view (similarly NSCollectionView), with the exception of using Core Animation. I'm quite far from him, and the last thing left to do is to implement scrolling.
My setup so far is that I have a subclass NSView(a supported layer), and upon initialization it creates and adds a mesh layer as a sublevel of the main layer of the view. I created a custom one CALayoutManagerfor the grid layer, which arranges its subzones as a grid. As expected, when I add sublayers to the mesh layer, the layout manager is called and the layers are set automatically. Up to this point, everything works as it should.
The problem occurs when I try to use NSScrollViewmy custom view as the parent to implement scrolling. I set it as follows: I created my custom view as a subtask NSScrollViewin Interface Builder. Then, in my layout manager class, I added a property delegate, and during initialization, my view subclass sets itself up as a layout manager delegate. At the end of layoutSublayersForLayer:the layout manager method , I invoke its delegate using the delegate method layoutManager:contentHeightChanged:. Here is the implementation of this method in my subclass NSView:
- (void)layoutManager:(MyLayoutManager*)manager contentHeightChanged:(CGFloat)height;
{
CGFloat newHeight = [[self enclosingScrollView] contentSize].height;
if (height > newHeight) {
newHeight = height;
}
NSRect newFrame = [self frame];
newFrame.size.height = newHeight;
[self setFrame:newFrame];
}
It's pretty simple, it just checks to see if the height of the new size is larger than the size of the scroll content, and sets the view frame to a new height.
- . , , , . : , . , :
http://vimeo.com/16987653
, , ( , ). , , , .
.