Pregunta

Tengo dos nsscrollview con desplazamiento sincronizado entre sí (usando Ejemplo de Apple) y está funcionando. A continuación, implementé un zoom que ampliaría ambas imágenes (tienen el mismo tamaño por definición). El código para el zoom se adaptó usando el código de aquí, que presento aquí:

    if (oldZoomValue > [sender floatValue]) // then we are zooming in
{
    float zoomFactor = 1 + oldZoomValue - [sender floatValue];

    oldZoomValue = [sender floatValue];

    NSRect visible = [synchroS_ScrollView documentVisibleRect];
    NSRect newrect = NSInsetRect(visible, NSWidth(visible)*(1 - 1/zoomFactor)/2.0, NSHeight(visible)*(1 - 1/zoomFactor)/2.0);
    NSRect frame = [synchroS_ScrollView.documentView frame];

    [synchroS_ScrollView.documentView scaleUnitSquareToSize:NSMakeSize(zoomFactor, zoomFactor)];
    [synchroS_ScrollView.documentView setFrame:NSMakeRect(0, 0, frame.size.width * zoomFactor, frame.size.height * zoomFactor)];
    [[synchroS_ScrollView documentView] scrollPoint:newrect.origin];

    NSRect visibleI = [synchroI_ScrollView documentVisibleRect];
    NSRect newrectI = NSInsetRect(visibleI, NSWidth(visibleI)*(1 - 1/zoomFactor)/2.0, NSHeight(visibleI)*(1 - 1/zoomFactor)/2.0);
    NSRect frameI = [synchroI_ScrollView.documentView frame];

    [synchroI_ScrollView.documentView scaleUnitSquareToSize:NSMakeSize(zoomFactor, zoomFactor)];
    [synchroI_ScrollView.documentView setFrame:NSMakeRect(0, 0, frameI.size.width * zoomFactor, frameI.size.height * zoomFactor)];

    [[synchroI_ScrollView documentView] scrollPoint:newrectI.origin];
}
else
{
// the equivalent but for zoom-out
}

Si uso la funcionalidad de zoom sin desplazamiento sincronizado, ambas imágenes en NSSCrollView se acercan muy bien como se esperaba. Sin embargo, si están sincronizados, el programa se bloquea con él parece ser una pila de varias llamadas: en el hilo principal, muestra muchas cosas como

#18 0x0000000100003e37 in -[SynchroScrollView synchronizedViewContentBoundsDidChange:] ()

Y en el GDB:

This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
sharedlibrary apply-load-rules all
[Switching to process 33162 thread 0x0]
[Switching to process 33162 thread 0xac03]
[Switching to process 33162 thread 0x903]
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
...
(gdb)

¿Alguien puede señalarme una dirección para la depuración o tener alguna idea de lo que está sucediendo? Gracias por tu ayuda.

¿Fue útil?

Solución

No estoy seguro de dónde llamas al código para hacer zoom en el ScrollView, pero tal vez el zoom en ScrollView A dispara el zoom en ScrollView B, que a su vez desencadena el zoom en ScrollView A nuevamente, creando un bucle interminable. Cambiar los límites en el synchronizedViewContentBoundsDidChange El método llamaría el mismo método una y otra vez.

Sé que esta pregunta tiene unos meses, pero tal vez esto ayuda :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top