这个问题是有关Get scroll bar position of an NSScroller on the fly获取上滚动
列表元素边界或框架,但现在我想知道如何在滚动获取列表元素(绿色矩形)的当前位置。
[self bounds]
或[self frame]
或[[self enclosingScrollView] ...]
不会为这种事情工作或我使用它错了。
编辑
里面的[[NSScrollView enclosingScrollView] contentView]]
框架,我们看到的NSBox
的名单。 当我的NSBox
三角这是列表元素,NSBox
的实例存储在-activeTicketRow
点击,我一直以为我可以再进去NSScrollView
框架NSBox
坐标时[[NSScrollView enclosingScrollView] contentView]]
范围的更改,但看完“查看编程指南”后,我可能不会。
我在NSScrollView
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(updateConvMenu:)
name:NSViewBoundsDidChangeNotification
object:[[self enclosingScrollView] contentView]
];
加入观察员和-updateConvMenu
我得到的[[self enclosingScrollView] contentView]
坐标,所以这是很好的。
问题
不,我想用来存储NSBox
(其中三角是点击)从[[self enclosingScrollView] contentView]
内-activeTicketRow
这样我就可以再得到它的框架坐标-updateConvMenu
当[[self enclosingScrollView] contentView]
范围的更改。
我觉得现在这个问题更具可读性。
它应该是相对于窗口。 当我使用'[self convertRect:[[[NSApp delegate] activeTicketRow] bounds] fromView:nil]'activeTabTicket'是列表元素,我得到了很好的坐标,但他们指向项目的原始位置,他们不当我滚动列表时改变。 – xyz 2011-03-21 16:24:05
什么是自我?你确定你想要窗口坐标吗?如果您尝试使用弹出式窗口,则几乎肯定需要屏幕坐标。您的-activeTicketRow的边界在哪个坐标空间中生存?你确定这一切都是你认为的吗?我不打赌。 – 2011-03-21 16:33:40
我真的认为你需要研究视图几何http://developer.apple。com/library/mac /#documentation/Cocoa/Conceptual/CocoaViewsGuide/Coordinates/Coordinates.html%23 // apple_ref/doc/uid/TP40002978-CH10-SW1 and view hierarchy http://developer.apple.com/library/ mac /#documentation/Cocoa/Conceptual/CocoaViewsGuide/Coordinates/Coordinates.html%23 // apple_ref/doc/uid/TP40002978-CH10-SW1 ... – 2011-03-21 16:34:53