Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Window/View Size Constraining



    The following code is my attempt to constrain a displayView and window
size such that the displayView maintains the proper aspect ratio when the
window is resized.  I have two issues:

1.  It sort of works. However, the displayView size tracking lags by at
least one time sample and I then have to gently nudge the window size to get
it right.

2.  This is a variable size window that is intended to show a miniature
display of what is in the main window (elsewhere).  I made an abortive
attempt to scale the coordinates of displayView.  Apparently, I don't
understand the "scaleUnitSquareToSize" call and the docs don't help.  Any
suggestions?


//    Window delegate for size
- (NSSize)windowWillResize:(NSWindow*)sender
                    toSize:(NSSize)frameSize
{
    //    displayView/controlView are outlets to top/bottom views in the
window.
    //    displayView has variable height, controlView fixed height.
    
    //    First, get the size of main view (elsewhere).
    NSSize fullSize = [[document
valueForKeyPath:@"course.props.presentaionSize"] sizeValue];
    float frameWidth = frameSize.width;
    //    Maintain aspect ratio of display view.
    float displayHeight = frameWidth * fullSize.height / fullSize.width;
    [displayView setFrameSize:NSMakeSize(frameWidth, displayHeight)];

    float controlViewHeight = [controlView frame].size.height;
    float winHeight = displayHeight + controlViewHeight;
    
//    Abortive attempt to scale display coordinates to fit.
//    float scale = frameWidth / fullSize.width;    //  Tried reciprocal
also.
//    [displayView scaleUnitSquareToSize:NSMakeSize(scale, scale)];
    
   return NSMakeSize (frameSize.width, winHeight);
}

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.