我试图通过指定滚动视图坐标内的矩形来放大 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 缩放比例,我如何缩放到矩形,以使其适合?
我想要实现的是照片应用程序的效果,其中裁剪网格被移动并且滚动视图缩放到该矩形。
有没有人知道一个链接或代码示例来实现与照片应用程序类似的效果?非常感谢。