从iPhone转到mac的开发者,会自然而然的以为NSView的subview(或控件)是有z轴顺序的,但实际上apple并不保证subview是按照添加的顺序显示。NSView也不存在类似于UIView的bringSubviewToFront方法。

应该避免subview之间有交集。但由于我是把我的iPhone项目转成mac,我并不像改变太多。还是找到了解决方法。就是在addSubview的时候使用以下方法:

[self addSubview:subviewFront positioned:NSWindowAbove relativeTo:subviewBack];

这样就明确了subviewFront在subviewBack后面绘制。如果relativeTo:nil,则在所有subview后面绘制。

(但,Interface Builder中建立的subview怎么办?)

参考资料:

http://www.cocoabuilder.com/archive/cocoa/169006-subview-ordering.html

http://stackoverflow.com/questions/2872840/how-do-i-make-an-nsview-move-to-the-front-of-all-nsviews

相关文章:

  • 2022-12-23
  • 2022-03-01
  • 2021-09-04
  • 2021-05-21
  • 2021-09-16
  • 2021-11-08
猜你喜欢
  • 2022-12-23
  • 2021-09-21
  • 2021-10-10
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案