2016 년 이었으므로 전체 크기의 콘텐츠보기가있는 활발한 제목 표시 줄을 사용하고 있습니다. 누군가가이를 수행 할 수있는 방법에 대한 생각을 추가하겠습니다. 바라기를 바란다면, 도움이 될 수있는 여기에 온 사람들에게 도움이 될 것입니다.
제목 표시 줄 아래로 스크롤하는 것과 관련하여 질문에 대답하지만,이 기술을 수정하여 인세 트 및 캐럿 위치를 사용하여 다른 것들을 스크롤 할 수 있습니다.
은, 당신이 사용할 수있는 (또는 그것의 내부를 NSTextView없이)를 제목 표시 줄 뒤에 스크롤 스크롤 뷰를 얻으려면 :
// For transparent title.
window.titlebarAppearsTransparent = true
window.styleMask = window.styleMask | NSFullSizeContentViewWindowMask
window.appearance = NSAppearance(named: NSAppearanceNameVibrantLight)
이 효과적으로 창의있는 contentView 위에 NSWindow 표시의 제목 표시 줄을 오버레이. (
// Make a constraint for SOMEVIEW to the top layout guide of the window:
let topEdgeConstraint = NSLayoutConstraint(
item: SOMEVIEW, attribute: NSLayoutAttribute.Top,
relatedBy: NSLayoutRelation.Equal,
toItem: window.contentLayoutGuide,
attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 0.0)
// Turn the constraint on automatically:
topEdgeConstraint.active = true
이것은 당신이 제목 표시 줄의 맨 아래에 요소의 상단을 제한 할 수 있으며 또는 도구 모음 + 하나를 :
는 제목 표시 줄의 높이를 모른 채 창 상단에 뭔가를 제한하려면 액세서리보기). 이는 2015 년 WWDC에서 나타났다 :
https://developer.apple.com/videos/play/wwdc2014/220/
은, 제목 표시 줄 아래로 스크롤하지만 윈도우의 unobscured 일부 내부의 스크롤 막대를 표시 할 수있는 ScrollView를 얻을 수 IB 또는 코드를 통해 콘텐츠 뷰의 상단에 고정하려면 이는 제목 표시 줄 아래에 표시됩니다. 마지막으로
scrollView.automaticallyAdjustsContentInsets = true
당신은 당신의 윈도우를 서브 클래 싱 커서/캐럿 위치를 처리 할 수 있습니다 다음, 그것은 자동으로 세트의 업데이트 할 말해. 스크롤 뷰의 내용 인세 트 위 또는 아래로 이동할 때 scrollview가 항상 커서/캐럿으로 스크롤하지 않도록하는 버그 (또는 개발자 측 오류)가 있습니다.
이 문제를 해결하려면 수동으로 캐럿 위치를 찾고 선택 항목이 변경되면 스크롤하여보아야합니다. 내 끔찍한 코드를 용서해 줘.하지만 일을 끝내는 것 같아. 이 코드는 NSWindow 서브 클래스에 속하므로 self
이 창을 참조합니다.
// MARK: NSTextViewDelegate
func textViewDidChangeSelection(notification: NSNotification) {
scrollIfCaretIsObscured()
textView.needsDisplay = true // Prevents a selection rendering glitch from sticking around
}
// MARK: My Scrolling Functions
func scrollIfCaretIsObscured() {
let rect = caretRectInWindow()
let y: CGFloat = caretYPositionInWindow() - rect.height
// Todo: Make this consider the text view's ruler height, if present:
let tbHeight: CGFloat
if textView.rulerVisible {
// Ruler is shown:
tbHeight = (try! titlebarHeight()) + textViewRulerHeight
} else {
// Ruler is hidden
tbHeight = try! titlebarHeight()
}
if y <= tbHeight {
scrollToCursor()
}
}
func caretYPositionInWindow() -> CGFloat {
let caretRectInWin: NSRect = caretRectInWindow()
let caretYPosInWin: CGFloat = self.contentView!.frame.height - caretRectInWin.origin.y
return caretYPosInWin
}
func caretRectInWindow() -> CGRect {
// My own version of something based off of an old, outdated
// answer on stack overflow.
// Credit: http://stackoverflow.com/questions/6948914/nspopover-below-caret-in-nstextview
let caretRect: NSRect = textView.firstRectForCharacterRange(textView.selectedRange(), actualRange: nil)
let caretRectInWin: NSRect = self.convertRectFromScreen(caretRect)
return caretRectInWin
}
/// Scrolls to the current caret position inside the text view.
/// - Parameter textView: The specified text view to work with.
func scrollToCursor() {
let caretRectInScreenCoords = textView.firstRectForCharacterRange(textView.selectedRange(), actualRange: nil)
let caretRectInWindowCoords = self.convertRectFromScreen(caretRectInScreenCoords)
let caretRectInTextView = textView.convertRect(caretRectInWindowCoords, fromView: nil)
textView.scrollRectToVisible(caretRectInTextView)
}
enum WindowErrors: ErrorType {
case CannotFindTitlebarHeight
}
/// Calculates the combined height of the titlebar and toolbar.
/// Don't try this at home.
func titlebarHeight() throws -> CGFloat {
// Try the official way first:
if self.titlebarAccessoryViewControllers.count > 0 {
let textViewInspectorBar = self.titlebarAccessoryViewControllers[0].view
if let titlebarAccessoryClipView = textViewInspectorBar.superview {
if let view = titlebarAccessoryClipView.superview {
if let titleBarView = view.superview {
let titleBarHeight: CGFloat = titleBarView.frame.height
return titleBarHeight
}
}
}
}
throw WindowErrors.CannotFindTitlebarHeight
}
희망이 있습니다.
문서의 크기가 조정되지 않은 경우에도이를 수행하고 싶습니다 ... 예를 들어 사용자가 많이 입력 할 때 scrollview는 내용을 클립하지 않아야합니다. scrollview 프레임 안에 들어 가지 않는 텍스트는 scrollview 범위 밖에 있어야합니다. – nacho4d