Objective-Cのnsscrollviewの画像をズームします
-
27-10-2019 - |
質問
スクロールが相互に同期した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)
誰かが私にデバッグの方向性を向けたり、何が起こっているのか考えてもらえますか?ご協力ありがとうございました。
解決
ScrollViewをズームするためのコードをどこに呼び出すかはわかりませんが、Scrollview a Scrollview BのトリガーAズームをズームすると、ScrollView Aのズームが再びトリガーされ、無限のループが作成されます。の境界を変更します synchronizedViewContentBoundsDidChange
メソッドは同じメソッドを何度も呼び出します。
私はこの質問が数ヶ月であることを知っていますが、多分これは役立ちます:)
所属していません StackOverflow