2014-01-22 3 views
2

사용자가 NSTextView를 스크롤하여 텍스트의 마지막 줄이보기의 맨 위에 오도록하고 싶습니다.. 기본적으로 한 페이지 이상의 텍스트가있는 NSTextView는 마지막 텍스트 줄이보기의 맨 아래에 올 때까지 사용자가 스크롤 할 수있게합니다. 이것을 어떻게 할 수 있습니까?NSTextView의 끝에서 스크롤을 허용하는 방법?

답변

3

NSLayoutManager를 서브 클래 싱하고 문제의 NSTextView에 서브 클래스를 할당하십시오. 그것은 텍스트의 마지막 줄을 레이아웃하라는 요청을 받았을 때 감지하고 훨씬 더 큰 rect를 반환하는 아주 간단한 방법입니다.

- (void)setExtraLineFragmentRect:(NSRect)fragmentRect usedRect:(NSRect)usedRect textContainer:(NSTextContainer *)container; 

// Sets the bounds and container for the extra line fragment. The extra line fragment is used when the text backing ends with a hard line break or when the text backing is totally empty, to define the extra line which needs to be displayed at the end of the text. If the text backing is not empty and does not end with a hard line break, this should be set to NSZeroRect and nil. Line fragment rects and line fragment used rects are always in container coordinates. 

NSTextView의 크기 조정 방법을 서브 클래스 화하고 그 안에 공간을 추가하는 방법도 있습니다. 마찬가지로, -setFrameSize :를 서브 클래 싱 해보고 (scrollView의 내용 영역 높이) - (텍스트의 마지막 줄 높이)를 추가하고 super를 호출하면 어떻게되는지보십시오.

+0

감사합니다. 다음 두 가지 아이디어를 모두 시도해 보겠습니다. – alltom

+0

'fragmentRect'의 크기를 늘리더라도 스크롤 영역이 확장되지 않습니다. 'usedRect'를 늘리면 커미션이 크게 커집니다. :) – alltom

+0

좋아, 나는 시도 할 다음 일로 내 대답을 업데이 트했습니다. –