开发者

Get list element bounds or frame on scrolling

开发者 https://www.devze.com 2023-02-18 14:44 出处:网络
this question is related to Get scroll bar position of an NSScroller on the fly 开发者_如何学JAVABut now i would like to know how to get current position of list element (green rect)on scrolling.

this question is related to Get scroll bar position of an NSScroller on the fly

开发者_如何学JAVA

But now i would like to know how to get current position of list element (green rect) on scrolling.

Get list element bounds or frame on scrolling

[self bounds] or [self frame] or [[self enclosingScrollView] ...] won't work for this kind of thing or i'm using it in wrong way.

EDIT

Inside frame of [[NSScrollView enclosingScrollView] contentView]] we see list of NSBox's. When i click on triangle of NSBox which is list element, instance of that NSBox is stored in -activeTicketRow, i've thought that i can then get NSBox coordinates inside NSScrollView frame when [[NSScrollView enclosingScrollView] contentView]] bounds changes, but after reading "View Programming Guide" i guess not.

I've added observer in NSScrollView

[[NSNotificationCenter defaultCenter] 
    addObserver:self
    selector:@selector(updateConvMenu:)
    name:NSViewBoundsDidChangeNotification
    object:[[self enclosingScrollView] contentView]
];

and in -updateConvMenu i get coordinates of [[self enclosingScrollView] contentView], so that's good.

QUESTION

No i would like to store NSBox (which triangle was clicked) from [[self enclosingScrollView] contentView] inside -activeTicketRow so i can then get it's frame coordinates in -updateConvMenu when [[self enclosingScrollView] contentView] bounds changes.

I think now this question is more readable.


Views are in a hierarchy. Ask yourself "position relative to what view/window/screen?" Then use NSView's various -convertRect:... or NSWindow's -convert... methods.


You can get the position of the content view by observing the NSClipViews (the scroll view's contentView) bounds by setting - (void)setPostsBoundsChangedNotifications:YES. Then just translate the coordinates to the view you want, when the notification occurs.

For the translation have a look at the docs Josh did already post View Programming Guide


When scrolling through the list, i'm calculating whether the horizontal center of the selected item in the list does not go after a specific bounds, which overlaps on [NSScrollView frame].

0

精彩评论

暂无评论...
验证码 换一张
取 消