我想通过指定在scrollview的坐标内的矩形来放大UIScrollView。然而,它没有按预期工作。我认为这是因为缩放比例或者我错过了转换。我试图缩放的滚动视图来自Apple的示例PhotoScroller - ImageScrollView。此外,我复制的代码来生成一帧从苹果公司的例子来缩放,以及:UIScrollView放大到矩形
- (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缩放比例,以便它适合正确?
我想要实现的是照片应用的效果,其中裁剪网格被移动并且scrollview缩放到那个矩形。
有没有人知道链接或代码示例来实现类似的照片应用程序的效果?非常感谢。