Re: view content not tracking window size
Re: view content not tracking window size
- Subject: Re: view content not tracking window size
- From: Ken Thomases <email@hidden>
- Date: Fri, 26 Sep 2014 00:49:35 -0500
On Sep 25, 2014, at 9:38 PM, N!K <email@hidden> wrote:
> In Xcode 5 OSX, not ios, I have created a custom view and set auto layout constraints so that the custom view's sides stay a fixed distance from the content view's frame. The custom view resizes correctly while dragging the window's corner while running, but the content of the custom view remains fixed in size. Shrinking the window can crop the content, and expanding it provides lots of open space next to the unchanging content.
>
> The content consists of a Bezier path, which is created in initwithframe and executed in drawrect with [path stroke]. NSLog shows that bounds is changing while resizing.
>
> How can I make the content resize along with the view and window? The window, view, and drawing documents explain how to set up a view, but I haven't found any discussion of content tracking the window size.
You asked this at <http://stackoverflow.com/questions/26006747/xcode-5-auto-layout-view-stretches-but-not-the-views-contents/26007383#26007383> and I answered you there.
In summary, the easiest thing to do is set the bounds once. If you ever set the bounds of a view, then they stop automatically tracking the frame. Therefore, the coordinate space ends up scaling. Since the bounds are no longer always equal to the frame, Cocoa effectively has to transform the coordinate space inside the view to the coordinate space of the containing view(s) and, ultimately, the window. That transform is exactly the sort of stretching you seem to be expecting.
What you set the bounds to is up to you. You could set the bounds to the unit square and then do all of your calculations based on the fraction of the view that you want to measure. So, x = 0 would be the left edge and x = 1 would be the right edge. x = 0.5 would be the center. x = 1/3.0 would be one third of the way across. Etc.
Regards,
Ken
_______________________________________________
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