我有两个滚动相互同步的 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)
谁能指出我的调试方向或知道发生了什么?感谢您的帮助。