它是一個熟悉的主題我使用UIScrollview創建圖形小說。該計劃是能夠與頂級uiscrollview沿着小說頁面。其中有一系列嵌套的uiscrollviews,每個嵌入uimageview。這個想法是,大圖像可以平移並放大,但仍然可以分頁。我有這個工作的大部分,但我不能讓縮放工作。我已經實現了縮放代理方法,但無濟於事,縮放只是平移圖像。我懷疑這是由於嵌套滾動視圖的嵌入性,但我不知道我缺少什麼。我看了一下Apple的scrollview套件示例,但無法找到答案。縮放嵌套的UIScrollViews
這是我迄今爲止的工作:
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
scrollview.pagingEnabled = YES;
scrollview.scrollEnabled =YES;
scrollview.clipsToBounds = NO;
scrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollview.showsHorizontalScrollIndicator = YES;
scrollview.backgroundColor = [UIColor blackColor];
NSInteger viewcount=4;
NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:@"mars.png"],[UIImage imageNamed:@"mercury.png"],[UIImage imageNamed:@"neptune.png"],[UIImage imageNamed:@"venus.png"],nil];
for (int i = 0; i <viewcount; i++)
{
CGFloat x = i * self.view.frame.size.width;
subView = [[UIScrollView alloc]initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, self.view.frame.size.height)];
[subView setBackgroundColor:[UIColor blackColor]];
[subView setCanCancelContentTouches:NO];
subView.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
subView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
aImageView = [[UIImageView alloc ] initWithImage:[images objectAtIndex:i]];
[self.aImageView setTag:ZOOM_VIEW_TAG];
[subView addSubview:aImageView];
[subView setContentSize:CGSizeMake(aImageView.frame.size.width, subView.frame.size.height)];
subView.minimumZoomScale = 1;
subView.maximumZoomScale = 3;
subView.delegate = self;
[subView setScrollEnabled:YES];
subView.contentSize = aImageView.frame.size;
[scrollview addSubview:subView];
[subView release];
}
[self.view addSubview:scrollview];
}
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView {
NSLog (@"test");
UIView * view = nil;
view = [subView viewWithTag:ZOOM_VIEW_TAG];
return view;
}
無法立即檢查,但是看看userInteractionEnabled對UIScrollView的默認值是否爲YES。我記得添加子視圖的方式與你完全一樣,因爲我想實現同樣的目的。同時檢查可能會干擾觸摸事件的其他標誌。 – TheBlack 2011-05-12 01:10:35