2013-07-23 56 views
0

我正在向UIScrollView添加許多UIImageView,並啓用了分頁功能。我只需放大縮放的圖像,而不是放大整個scrollview。縮放特定圖像不會縮小擴大其他子視圖。只縮放從UIScrollView選定的子視圖

- (void)loadScrollViewWithImages { 

scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * imageList.count, self.view.bounds.size.height); 
scrollView.pagingEnabled = YES; 
UIView *mainView = [[UIView alloc] initWithFrame:self.view.bounds]; 

CGFloat xPos = 0.0; 
for (UIView *subView in scrollView.subviews) { 
    [subView removeFromSuperview]; 
} 

int i = 0; 

for (NSDictionary *imageDetails in self.imageList) { 

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xPos, 0.0, self.view.bounds.size.width, self.view.frame.size.height)]; 
    imageView.contentMode = UIViewContentModeScaleAspectFill; 
    [imageView setClipsToBounds:YES]; 
    [mainView addSubview:imageView]; 
    xPos += self.view.bounds.size.width; 

    [imageView setImageWithURL:[NSURL URLWithString:[imageDetails objectForKey:@"media_path"]]]; 

    [self.imageViewArray addObject:imageView]; 

    if(self.selectedImageIndex == i) { 
     self.selectedImageView = imageView; 
    } 
    i++; 
} 
[mainView setFrame:CGRectMake(mainView.frame.origin.x, mainView.frame.origin.x,self.view.bounds.size.width * imageList.count, self.view.bounds.size.height)]; 
[scrollView addSubview:mainView]; 

}

我想放大僅選定的索引,但其他子視圖還增加了屏幕縮​​放。

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

}

回答

0

用於實現該你必須採取一個主要滾動視圖作爲已拍攝並且代替在此滾動視圖顯示的ImageView你必須採取另一個滾動視圖並顯示該圖像,並且當用戶嘗試縮放圖像,然後只滾動選定的滾動視圖。

相關問題