2014-04-17 3 views
2

맨 아래로 스크롤 할 때 스크롤 위치를 어떻게 찾을 수 있습니까?NSScrollView는 스크롤 위치를 감지합니다.

[[_scrollView contentView] setPostsBoundsChangedNotifications:YES]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(boundsDidChangeNotification:) 
              name:NSViewBoundsDidChangeNotification 
              object:[_scrollView contentView]]; 





- (void) boundsDidChangeNotification: (NSNotification *) notification 
{ 
    NSPoint currentScrollPosition = [[_scrollView contentView] bounds].origin; 
} 
+0

'UIScrollViewDelegate'를 구현 했습니까? (https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/reference/uiscrollviewdelegate.html) – Popeye

+0

문서에서 정보를 찾을 수 없습니다 ... OS X 코드입니다. IOS가 아님 – realmasse

+0

알림이 실행되는지 확인 했습니까? – Wain

답변

2
if (_scrollView.verticalScroller.floatValue > 0.9) 
{ 
    // bottom 
    // do something 
} 
+0

해결되었습니다! 감사합니다 – realmasse

8

당신은 경계 대신 NSScrollView의있는 contentView의 가시 RECT를 사용할 수 있습니다

- (void)boundsDidChangeNotification:(NSNotification*) notification 
{ 
    NSRect visibleRect = [[_scrollView contentView] documentVisibleRect]; 
    NSLog(@"Visible rect:%@", NSStringFromRect(visibleRect)); 
    NSPoint currentScrollPosition = visibleRect.origin; 
} 

내용보기 경계가 원래 코드에서, 그래서 스크롤하는 동안 변경되지 않습니다 , bounds.origin은 아마 항상 0/0을 반환합니다.

+0

이것은 IMO가 더 나은 대답이되어야합니다. –

+0

스크롤하는 동안 내용보기의 원본이 변경됩니다. 어쩌면 당신은 문서보기를 생각하고 있었을 것입니다. – JWWalker

관련 문제