简体   繁体   中英

View bounds and coordinates in Cocoa Mac OS X

I have a simple custom view in my Mac OS X application that is essentially empty. Here is the code:

@implementation MyDrawingView

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }

    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    NSLog(@"bounds:x:%f y:%f w:%f h:%f", self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.bounds.size.height);
}

@end

Here is the output of NSLog:

bounds:x:0.000000 y:0.000000 w:713.000000 h:509.000000

I read about user space here: Coordinate Systems and Transforms

Does this mean that my view is going to show 713/72 inches wide on screen? It doesn't show up that wide in reality. I have a background color set on my view so I can see it just as wide as it really is.

the view is 713 points wide. 713*screenscale = pixel size which you can then use with dpi to get the inches shown ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM