0

我正在尝试缩放并且在它使用滚动视图中的图像之前。现在我试图用 ViewController 替换该图像并放大该 ViewController 中的对象。它不工作。

viewDidLoad:

- (void)viewDidLoad
{
self.boardView = [[BoardViewController alloc] init];
[self.scrollView addSubview:self.boardView.view];

[self.scrollView setContentSize:(CGSizeMake(320, 320))];

UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewDoubleTapped:)];
doubleTapRecognizer.numberOfTapsRequired = 2;
doubleTapRecognizer.numberOfTouchesRequired = 1;
[self.scrollView addGestureRecognizer:doubleTapRecognizer];

viewForZoomingInScrollView:

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [self.scrollView.subviews objectAtIndex:0];

doubleTapped 方法:(当我在其中输入日志时它正在调用它,它只是没有缩放。

- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer {

CGPoint pointInView = [recognizer locationInView:self.boardView.view];

CGFloat newZoomScale = self.scrollView.zoomScale * 3.0f;
if (self.scrollView.zoomScale > self.scrollView.minimumZoomScale){
newZoomScale = MIN(newZoomScale, self.scrollView.minimumZoomScale);
}
else {
    newZoomScale = MIN(newZoomScale, self.scrollView.maximumZoomScale);
}

CGSize scrollViewSize = self.scrollView.bounds.size;

CGFloat w = scrollViewSize.width / newZoomScale;
CGFloat h = scrollViewSize.height / newZoomScale;
CGFloat x = pointInView.x - (w / 2.0f);
CGFloat y = pointInView.y - (h / 2.0f);

CGRect rectToZoomTo = CGRectMake(x, y, w, h);

[self.scrollView zoomToRect:rectToZoomTo animated:YES];

我不明白它有什么问题。

4

0 回答 0