iphone viewForZoomingInScrollView未调用

时间:2013-02-25 12:59:56

标签: iphone ipad uiscrollview

编辑:我的控制器包含uiscrollview。该scrollview包含自定义uiview,其独立的类继承自uiview。该uiview将uiimageview作为子视图。不,我正在主控制器中“(UIView *)viewForZoomingInScrollView :( UIScrollView *)scrollView”。但是当我缩放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
}

2 个答案:

答案 0 :(得分:19)

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

self. scrollViewPresentation.minimumZoomScale = 1.0;
self. scrollViewPresentation.maximumZoomScale = 10.0;

答案 1 :(得分:0)

只有在你开始变焦后才会调用它。视图应该是scrollview的子视图,保持对它的引用作为属性并在委托方法中返回:

- (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;
}