我有UIScrollView包含3 * UIImageView,每個UIImageView都有一個圖像。 碼我用:UIScrollView + UIImageView放大/縮小
scrollView.delegate = self;
[self.scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 0.75;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSUInteger nimages = 0;
CGFloat cx = 0;
for (; ; nimages++) {
NSString *imageName = [NSString stringWithFormat:@"%d.jpg", (nimages + 1)];
UIImage *image = [UIImage imageNamed:imageName];
if (image == nil) {
break;
}
imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = image.size.height;
rect.size.width = image.size.width;
rect.origin.x = ((scrollView.frame.size.width - image.size.width)/2) + cx;
rect.origin.y = ((scrollView.frame.size.height - image.size.height)/2);
[imageView setFrame:CGRectMake(cx, 0, self.view.frame.size.width, self.view.frame.size.height)];
[scrollView addSubview:imageView];
[imageView release];
cx += scrollView.frame.size.width;
}
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
我怎樣才能使滾動型使用變焦能夠多點觸控? 我用這個代碼:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
但它並沒有正常工作,圖像重疊得到,因爲滾動型包含多張圖片。
我該如何解決? 感謝
子視圖沒有子視圖;) – Bejil