2012-10-12 74 views
0

我主要UIScrollView滾動視圖子uiscrollviews的UIImageView viewForZoomingInScrollView

mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)]; 
mainScrollView.pagingEnabled = YES; 
imageScrollView.contentSize = CGSizeMake(320 * [myImage count], 440); 

,其中包含許多子UIScrollView,每個子UIScrollView包含UIImageView

for (int i = 0; i < [myImage count]; i++) 
{ 
    imageView = [[UIImageView alloc] init]; 
    [imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 

    NSString *strimage = [myImage objectAtIndex:i]; 
    NSURL *imageUrl = [NSURL URLWithString:strimage]; 

    [imageView setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"Placeholder"]]; 

    imageView.frame = CGRectMake(0, 0, 320, 440); 

    subScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(320 * i, 0, 320, 440)]; 
    subScrollView.contentSize = 
    CGSizeMake(imageView.frame.size.width, imageView.frame.size.height); 
    subScrollView.pagingEnabled = YES; 
    subScrollView.showsHorizontalScrollIndicator = NO; 
    subScrollView.showsVerticalScrollIndicator = NO; 
    subScrollView.delegate = self; 
    subScrollView.bouncesZoom = YES; 
    subScrollView.clipsToBounds = YES; 

    subScrollView.maximumZoomScale = 3.0; 
    subScrollView.minimumZoomScale = 1.0; 
    subScrollView.zoomScale = 1.0; 

    [mainScrollView addSubview:subScrollView]; 
    [subScrollView addSubview:imageView]; 
} 

,我實現

#pragma mark UIScrollViewDelegate methods 

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { 
    return imageView; 
} 

概率LEM是,當我在UIImageView放大,假設有3個子UIScrollView,最後的副UIScrollView可以放大UIImageView正常,但其他2,當我在它放大,但放大子UIScrollView代替UIImageView,它影響的最後一個子UIScrollView到也變焦,我做錯了什麼?

我懷疑在viewForZoomingInScrollView,它只能縮放最後UIImageView(最後一個子UIScrollView)。

預先感謝您:)

+0

看來,我認爲我分開的子UIScrollView,但可能它不是:( – piam

回答

1

最後我想通了,我只需要更新我UIImageView當我在特定UIImageView 放大 - (UIView的*)viewForZoomingInScrollView:(UIScrollView的*)滾動視圖是這樣的:

#pragma mark - 
#pragma mark UIScrollViewDelegate methods 

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { 
    for (UIImageView *iv in [scrollView subviews]) { 
     imageView = iv; 
     break; 
    } 

    return imageView; 
} 

希望它可以幫助某人,在這一點上與我鬥爭,所以你不必浪費時間:)。

相關問題