简体   繁体   English

将子视图添加到NSView

[英]Adding subviews to NSView

I want to add subview to NSView dynamically. 我想将子视图动态添加到NSView。 I set the coordinates of NSView as : 我将NSView的坐标设置为:

NSView *tmpView = [[NSView alloc]initWithFrame:self.view.frame];

I want to add dynamic number of imageViews to tmpView. 我想将动态数量的imageViews添加到tmpView。 My imageView is as: 我的imageView是:

NSImageView *tmpImageView = [[NSImageView alloc]initWithFrame:CGRectMake(xAxis, yAxis, 320, 180)];

Here, xAxis and yAxis are for positioning of imageViews dynamically. 在这里,xAxis和yAxis用于动态定位imageViews。

When i add image view to NSView as: 当我将图像视图添加为NSView时:

[tmpView addSubView:tmpImageView]

It adds imageView from bottom left corner but i want it to start from top left corner. 它从左下角添加了imageView,但我希望它从左上角开始。 Please help how can i add subViews accordingly to NSView. 请帮助我如何将子视图相应地添加到NSView。

Thanks in advance 提前致谢

The easiest way is to subclass your view and override -isFlipped to return YES . 最简单的方法是对视图进行子类化,并覆盖-isFlipped返回YES See the NSView documentation where it says: 请参阅NSView文档 ,其中显示:

-(BOOL)isFlipped -(BOOL)已翻转
Returns YES if the receiver uses flipped drawing coordinates or NO if it uses native coordinates. 如果接收器使用翻转的图形坐标,则返回YES;如果接收器使用本机坐标,则返回NO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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