开发者

Resizing NSView to accommodate subviews

I'm having an extreme amount of difficulty in getting my PXListView and NSScrollView setup to work nicely. Here's the gist of it:

I have a dashboard page that is to contain 2 PXListViews. One of them gets its data from Core Data, the other from an RSS Feed. Both of these are added to a superview and associated controller (I have modes other than Dashboard so this was the most efficient way). This superview becomes the documentView for my NSScrollView.

I can get all of this to work nicely except with the RSS feed based List View. I am getting the feed asynchronously so that it doesn't hold up the UI and once a feed has been received and the List View populated I have it automatically resize itself. This all works great, however I then need to resize my Dashboard View in order to get the scrollbars up. So I send a notification which leads to an autosizeView method I created but it all goes to hell.

The two ListViews start to overlap and the contents of the top one end up in the bottom one. Screenshot below (red is the b开发者_开发百科ounds rectangle, blue the frame of each Subview)

This is before calling autosizeView:

Resizing NSView to accommodate subviews

This is after calling it:

Resizing NSView to accommodate subviews

And for good measure, this is what it looks like if I resize the PXListViews and don't call the DashboardView's autosize method:

Resizing NSView to accommodate subviews

As you can see, it works fine as long as I don't call autosizeViews but then I don't get the scrollers happening. Here is my autosizeView method:

-(void)autosizeView
{
    //Resize the view to accommodate all subviews
    NSRect oldFrame = [[self view] frame];
    CGFloat lastY = [_activityView frame].origin.y;
    if (lastY < 0) {
        CGFloat newHeight = oldFrame.size.height + (-lastY);
        [[self view] setFrameSize:NSMakeSize(oldFrame.size.width, newHeight)];
    }
}

I'm guessing this whole thing has something to do with the coordinates being mucked up when I resize the DashboardView, causing the origins of its subviews to go awry.

Any help will be greatly appreciated!!!


Well I ended up solving it. The glitchiness turns out to have been caused by the PXListView's automatically changing their heights as their superview resized. A quick change use setAutoresizeMask: was all that was needed. It's always something simple hey?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜