• 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
Strange stretching NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange stretching NSView


  • Subject: Strange stretching NSView
  • From: Ken Tozier <email@hidden>
  • Date: Thu, 1 Feb 2007 14:38:36 -0500

Hi

I'm sure this is just a coordinate problem but I've been trying for about four hours and can't figure it out. Basically, I'm creating a custom view that wraps it's content views (similar to the iPhoto thumbnail view) and what's happening is that the wrapping view itself is more than twice as deep as I tell it to be and all subviews are rendering with incorrect frame sizes. I tell them to size to 27 x 34 pixels and they are displaying at 23 x 84 pixels.

I've tried each of the following with no success

- set the "isFlipped" to return both YES and NO
- set the setAutoresizingMask to NSViewWidthSizable for the containing view and NSViewNotSizable for the subviews
- query container and subviews for their size at runtine (all values correct)
- checked frame values to make sure I wasn't flopping width for height and vice versa


I'm stumped. Anyone have an idea why views would stretch despite the fact that, when queried for their size at runtime, all views return correct values?

Any help appreciated

Ken

Here's the wrapping view initializer

- (id) initWithFrame:(NSRect) frame
{
    self = [super initWithFrame: frame];
    if (self)
	{
        // Initialization code here.
		indent			= 10;
		horizSpacing	= 5;
		vertSpacing		= 8;
		pages			= [[NSMutableDictionary alloc] init];
		pageWidth		= [KPage defaultWidth];
		pageHeight		= [KPage defaultHeight];
		maxHeight		= 2 * indent + 3 * vertSpacing + 4 * pageHeight;
		pageCount		= 0;

		[self updateGeometry];

		[self setAutoresizingMask: NSViewWidthSizable];
	}

    return self;
}

Here's the wrapping view "updateGeometry" method:

- (void) updateGeometry
{
int width = [self bounds].size.width,
remainder;

pageCount = [pageRecords count];
usableWidth = width - 2 * indent;
pagesPerRow = (usableWidth - horizSpacing) / (pageWidth + horizSpacing);
remainder = ((pageCount % pagesPerRow) > 0) ? 1 : 0;
rowCount = (pageCount / pagesPerRow) + remainder;
totalHeight = pageHeight * rowCount + vertSpacing * (rowCount - 1) + 2 * indent;
rightMax = width - indent;
}


Here's the relevant part of the wrapping view "drawRect" method:

if (recordsChanged == YES)
{
	NSRect				pageFrame;

	NSEnumerator		*enumerator		= [pageRecords objectEnumerator];
	NSDictionary		*pageRecord;
	KPage				*page;
	NSNumber			*key;

	int					top				= indent,
						left			= indent;

	// delete all the old pages
	[pages removeAllObjects];

	// add the new pages
	while (pageRecord = [enumerator nextObject])
	{
		// check for right edge
		if ((left + horizSpacing + pageWidth) > rightMax)
		{
			// create a new row
			left			= indent;
			top			+= (pageHeight + vertSpacing);
		}

		pageFrame		= NSMakeRect(left, top, pageWidth, pageHeight);

		// get the page record ID
		key		= [pageRecord objectForKey: @"id"];

		// create the page
		page	= [KPage pageWithFrame: pageFrame record: pageRecord];

		// add page to page list
		[pages setObject: page forKey: key];

		// add page to view
		[self addSubview: page];

		// update variables for next pass
		left	+= (pageWidth + horizSpacing);
	}

	// reset recordsChanged
	recordsChanged		= NO;
}

And here's the KPage initializer:

- (id) initWithFrame:(NSRect) frame
		record:(NSDictionary *) inPageRecord
{
	self = [super initWithFrame: frame];
	if (self)
	{
		// set properties
		record				= [inPageRecord retain];
		page				= [[record objectForKey: @"page_number"] intValue];
		oddPage			= [self isOddPage: page];
		active				= YES;

		// set sizing constraints
		[self setAutoresizingMask: NSViewNotSizable];

		// add elements
		pageField			= [[KPageNumberField alloc] initWithFrame: [self bounds]];
		[self addSubview: pageField];

		[self setPageNumber: page];
		[self updateImages];

		currentImage		= [self imageForKey: KViewStateInactive];
	}

	return self;
}




_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Prev by Date: Re: Initializing Subclass of NSTextContainer
  • Next by Date: CoreData - Turning to-many relationship back into a fault
  • Previous by thread: Re: Initializing Subclass of NSTextContainer
  • Next by thread: Re: Strange stretching NSView
  • Index(es):
    • Date
    • Thread