7

编辑:我有包含 uiscrollview 的控制器。该滚动视图包含自定义 uiview,其单独的类继承自 uiview。那个 uiview 有 uiimageview 作为子视图。不,我在主控制器中使用“(UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView”。但是当我缩放滚动视图时,该方法没有触发。我应该怎么做才能调用这个方法。

UIView *DrawingPlusImageView = [[UIView alloc]initWithFrame:CGRectMake((i*IMAGEVIEW_IPAD_LAND_X+112), 0, 800, 600)];

    IDDrawingView *drawView = [[IDDrawingView alloc]initWithFrame:CGRectMake(0, 0, 800, 600)];

    UIImageView* imgViewLand = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)];
    [imgViewLand setImage:[UIImage imageNamed:@"noFileSelected.png"]];
    [drawView setImageToDraw:imgViewLand.image];
    //        drawView.delegate = self;
    [drawView setCurrentSlidId:hmslide.strSlideID];
    [DrawingPlusImageView addSubview:imgViewLand];
    [DrawingPlusImageView addSubview:drawView];


    [scrollViewPresentation addSubview:DrawingPlusImageView];
    drawView.userInteractionEnabled = YES;

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
// Return the view that we want to zoom

return  [self.scrollViewPresentation.subviews objectAtIndex:1];// there are slides, im zooming the second
}
4

2 回答 2

21

我遇到了同样的问题。并为 ScrollView 设置最小和最大缩放级别解决了我的问题..尝试

self. scrollViewPresentation.minimumZoomScale = 1.0;
self. scrollViewPresentation.maximumZoomScale = 10.0;
于 2013-09-24T09:01:23.400 回答
0

只有在您开始缩放时才会调用它。视图应该是滚动视图的子视图,保留对它的引用作为属性并在委托方法中返回它:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.container];
    [self.container addSubview:self.imageView];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;
}
于 2014-05-29T18:48:31.540 回答