0

スクロールビューの座標内にある四角形を指定して、UIScrollView 内をズームしようとしています。ただし、期待どおりに機能していません。ズームスケールが原因か、変換が足りないと思います。ズームしようとしているスクロール ビューは、Apple のサンプル PhotoScroller -- ImageScrollView からのものです。また、コードをコピーして、Apple の例からもズームするフレームを生成しました。

- (CGRect)zoomRectForScrollView:(UIScrollView *)scrollView withScale:(float)scale withCenter:(CGPoint)center {

    CGRect zoomRect;

    // The zoom rect is in the content view's coordinates.
    // At a zoom scale of 1.0, it would be the size of the
    // imageScrollView's bounds.
    // As the zoom scale decreases, so more content is visible,
    // the size of the rect grows.
    zoomRect.size.height = scrollView.frame.size.height / scale;
    zoomRect.size.width  = scrollView.frame.size.width  / scale;

    // choose an origin so as to get the right center.
    zoomRect.origin.x = center.x - (zoomRect.size.width  / 2.0);
    zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);

    return zoomRect;
}

実際にズームするコードは次のとおりです。

CGPoint scrollRectCenter = CGPointMake(rect.origin.x + (rect.size.width /2) ,
                                       rect.origin.y + (rect.size.height / 2));
CGFloat newZoomScale = self.imageScrollView.zoomScale * 1.3f;
newZoomScale = MIN(newZoomScale, self.imageScrollView.maximumZoomScale);
CGRect zoomToRect = [self zoomRectForScrollView:self.imageScrollView withScale:newZoomScale withCenter:scrollRectCenter];
[self.imageScrollView zoomToRect:zoomToRect animated:YES];

ズームされたimageViewズームスケールを考慮して、正しく収まるように四角形にズームするにはどうすればよいですか?

私が達成しようとしているのは、クロップグリッドが移動され、スクロールビューがその四角形にズームする写真アプリの効果です。

写真アプリと同様の効果を達成するためのリンクまたはコード例を知っている人はいますか? どうもありがとう。

4

1 に答える 1