NSTextView dentro de un NSScrollView no se desplaza :(
-
01-10-2019 - |
Pregunta
tengo el código siguiente en una aplicación de prueba de cacao autónomo:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSView *contentView = [window contentView];
NSTextStorage *textStorage = [NSTextStorage new];
NSLayoutManager *layoutManager = [NSLayoutManager new];
NSTextContainer *textContainer = [NSTextContainer new];
[textContainer setHeightTracksTextView:YES];
[textContainer setWidthTracksTextView:YES];
[textStorage addLayoutManager:layoutManager];
[layoutManager addTextContainer:textContainer];
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:[contentView bounds]];
[scrollView setHasVerticalScroller:YES];
[scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[scrollView setBorderType:NSNoBorder];
NSRect textFrame;
textFrame.origin = NSZeroPoint;
textFrame.size = [NSScrollView contentSizeForFrameSize:[scrollView frame].size hasHorizontalScroller:NO hasVerticalScroller:YES borderType:NSNoBorder];
NSTextView *textView = [[[NSTextView alloc] initWithFrame:textFrame textContainer:textContainer] autorelease];
[textView setAutoresizingMask:NSViewWidthSizable];
[scrollView setDocumentView:textView];
[contentView addSubview:scrollView];
}
Estoy tratando de configurar toda la jerarquía de los objetos involucrados (incluyendo los objetos del sistema de texto) en una combinación NSTextView + NSScrollView sólo para ver cómo funciona todo en conjunto. Sin embargo cuando funciono esto y empezar a añadir un montón de líneas a la vista de texto, no desplazarse cuando el texto se hace más larga que la vista es alto. Es como si el NSScrollView y la NSTextView no son conscientes el uno del otro. ¿Qué conexiones son yo que falta para que todo aquí para comunicarse correctamente?
Editar : Sí, esto es con fugas y feo. :) Esto fue escrito sólo para tratar de determinar lo que está pasando aquí, no el código de producción o cualquier cosa que va a utilizar directamente nunca más. Promesa.
Solución
¿Usted ha intentado jugar con - setHorizontallyResizable: y - setVerticallyResizable:?