スクロールが互いに同期された2つの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)
誰でもデバッグの方向性を教えてもらえますか、または何が起こっているのか分かりますか? ご協力ありがとうございました。