我的 Mac OS X 应用程序中有一个简单的自定义 View ,它基本上是空的。这是代码:
@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
这是 NSLog 的输出:
bounds:x:0.000000 y:0.000000 w:713.000000 h:509.000000
我在这里阅读了有关用户空间的信息:Coordinate Systems and Transforms
这是否意味着我的 View 将在屏幕上显示 713/72 英寸宽?它在现实中并没有表现得那么广泛。我在 View 上设置了背景颜色,这样我就可以看到它与实际一样宽。
最佳答案
View 宽 713 点。 713*screenscale = 像素大小,然后您可以将其与 dpi 一起使用来获取显示的英寸;)
关于objective-c - 在 Cocoa Mac OS X 中查看边界和坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28581904/