質問

んが、それは常にできたてのNSView(myView)に包まれたNSScrollView(myScrollView).使用ズーム-in/outボタンで、ユーザが変更することが可能な規模のmyView.ユーザの場合は現在のスクロールに特定のスポットmyView思いる部分のビュー画面の後にズームします。

私のコードは以下のようなものです:

    // preserve current position in scrollview
    NSRect oldVisibleRect = [[myScrollView contentView] documentVisibleRect];
    NSPoint oldCenter = NSPointFromCGPoint(CGPointMake(oldVisibleRect.origin.x + (oldVisibleRect.size.width  / 2.0),
                                                       oldVisibleRect.origin.y + (oldVisibleRect.size.height / 2.0)));

    // adjust my zoom
    ++displayZoom;
    [self scaleUnitSquareToSize:NSSizeFromCGSize(CGSizeMake(0.5, 0.5))];
    [self calculateBounds];  // make sure my frame & bounds are at least as big as the visible content view
    [self display];

    // Adjust scroll view to keep the same position.
    NSRect newVisibleRect = [[myScrollView contentView] documentVisibleRect];
    NSPoint newOffset = NSPointFromCGPoint(CGPointMake((oldCenter.x * 0.5) - (newVisibleRect.size.width  / 2.0),
                                                       (oldCenter.y * 0.5) - (newVisibleRect.size.height / 2.0)));
    if (newOffset.x < 0)
        newOffset.x = 0;
    if (newOffset.y < 0)
        newOffset.y = 0;

    [[myScrollView contentView] scrollToPoint: newOffset];
    [myScrollView reflectScrolledClipView: [myScrollView contentView]];

るようになったようなあり、それまでのやまだひさしをはじめとする図うになっている間違っています。私の質問:

1)はありませ内蔵う、日:

   [myView adjustScaleBy: 0.5 whilePreservingLocationInScrollview:myScrollView];

2)ない場合は誰でもできるので見えになっている間違った自分の長周"アプローチしますのでご注意ください。▼

よろしく!

役に立ちましたか?

解決

のスクロール位置後のスケーリングは簡単なことではありません。ひとつのに必要なものを決定するかということは"同じ"といい、上、中、または底部の可視領域の前にスケーリング滞在した後、スケーリング?

または、より直感的にしたい位置に滞在する割合を見えるrectと同じ割合するスクロールを下書き(例えば、センターのラウジングの補助の親指を動かさないように上下に中規模で、親指だけが収縮する).

したい場合は、後者の効果、について教えてくださいではNSScrollViewのverticalScrollerとhorizontalScroller、その読みをfloatValueます。これらの規格化0から1には、'0'を意味だけでは文書の先頭の1手段にたたずんでいます。のもつかのラウジングの補助のためこの場合には文書よりも短いというNSScrollView、ラウジングの補助ものを返すメソ答えすべての場合は、"floatValue,'などで特別の場合です。

後にリサイズを設定しNSScrollViewのスクロール位置の同じ比率で前のスケールですが、残念は、私の波自分の手でチャレンジしましょう。俺はこのが私のコードがかったと記憶していだけではできない設定にNSScrollers''floatValueの直なんかスクロールさんに実際に影響するのNSScrollView.

なんて書き込む数学計算の左上の点でお客様の文書に基づき割合をしたいので、y軸、インスタンスで、"場の文書によるscrollViewのcontentView、スクロールポイントは0、それ以外のスクロールするポイントの高さのcontentView-高documentView)*oldVerticalPercentage)の書類です。" X軸のコースに似ています。

また、私はほぼ正の必要な呼び出し表示ここでは、一般的な話できます。(-setNeedsDisplay:でいただけます)。

-Wil

他のヒント

私はあなたがあまりにも入力したいと思って...; - )

// instead of this:
NSPoint oldCenter = NSPointFromCGPoint(CGPointMake(oldVisibleRect.origin.x +
    (oldVisibleRect.size.width  / 2.0),

// use this:
NSPoint oldCenter = NSMakePoint(NSMidX(oldVisibleRect), NSMaxY(oldVisibleRect));

// likewise instead of this:
[self scaleUnitSquareToSize:NSSizeFromCGSize(CGSizeMake(0.5, 0.5))];

// use this:
[self scaleUnitSquareToSize:NSMakeSize(0.5, 0.5)];

// and instead of this
NSPoint newOffset = NSPointFromCGPoint(CGPointMake(
    (oldCenter.x * 0.5) - (newVisibleRect.size.width  / 2.0),
    (oldCenter.y * 0.5) - (newVisibleRect.size.height / 2.0)));

// use this:
NSPoint newOffset NSMakePoint(
    (oldCenter.x - NSWidth(newVisibleRect)) / 2.f,
    (oldCenter.y - NSHeight(newVisibleRect)) / 2.f);

この古い質問ですが、私はこれを探して誰かが私の答えは便利...

見つけた願っています
float zoomFactor = 1.3;

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

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

    [[scrollView documentView] scrollPoint:newrect.origin];
}

-(void)zoomOut
{
    NSRect visible = [scrollView documentVisibleRect];
    NSRect newrect = NSOffsetRect(visible, -NSWidth(visible)*(zoomFactor - 1)/2.0, -NSHeight(visible)*(zoomFactor - 1)/2.0);

    NSRect frame = [scrollView.documentView frame];

    [scrollView.documentView scaleUnitSquareToSize:NSMakeSize(1/zoomFactor, 1/zoomFactor)];
    [scrollView.documentView setFrame:NSMakeRect(0, 0, frame.size.width / zoomFactor, frame.size.height / zoomFactor)];

    [[scrollView documentView] scrollPoint:newrect.origin];
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top