0

我有两个滚动相互同步的 NSScrollView(使用Apple 的示例)并且它正在工作。接下来我实现了缩放两个图像(根据定义它们具有相同的大小)。缩放的代码是使用这里的代码改编的,我在这里展示:

    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
}

如果我在没有同步滚动的情况下使用缩放功能,则 NSScrollView 上的两个图像都会按预期很好地缩放。但是,如果它们是同步的,程序崩溃似乎是几个调用的堆栈:在主线程上,它显示了很多类似的东西

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

在 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)

谁能指出我的调试方向或知道发生了什么?感谢您的帮助。

4

1 回答 1

0

我不确定你在哪里调用缩放scrollView的代码,但也许放大scrollView A会触发放大scrollView B,这反过来又会触发再次放大scrollView A,从而创建一个无限循环。更改方法中的边界 synchronizedViewContentBoundsDidChange将一次又一次地调用相同的方法。

我知道这个问题已经存在几个月了,但也许这有帮助:)

于 2011-11-15T09:02:38.537 回答