我想通過指定在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縮放到那個矩形。
有沒有人知道鏈接或代碼示例來實現類似的照片應用程序的效果?非常感謝。