我正在尝试缩放,然后才能使用滚动视图中的图像。现在我正在尝试用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];
我不明白它有什么问题。