我正在使用UIScrollView
。在该滚动视图中,我按顺序放置UIImageViews
。缩放无效。这是我的代码
- (void)viewDidLoad
{
self.view.backgroundColor=[UIColor blackColor];
NSArray *imageArray=[[NSArray alloc]initWithObjects:[UIImage imageNamed:@"test1.png"],[UIImage imageNamed:@"test2.png"],[UIImage imageNamed:@"test3.png"], nil];
scrollView_=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width+20, self.view.frame.size.height)];
[scrollView_ setCanCancelContentTouches:NO];
scrollView_.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView_.clipsToBounds = NO;
scrollView_.scrollEnabled = YES;
scrollView_.pagingEnabled = YES;
scrollView_.delegate=self;
scrollView_.showsHorizontalScrollIndicator=NO;
scrollView_.showsVerticalScrollIndicator=NO;
scrollView_.contentSize = CGSizeMake([imageArray count]*self.scrollView_.frame.size.width, self.scrollView_.frame.size.height);
[scrollView_ setMaximumZoomScale:3.0];
[scrollView_ setMinimumZoomScale:1];
[scrollView_ setZoomScale:1];
[scrollView_ setBouncesZoom:YES];
[scrollView_ setBounces:YES];
for(int i=0;i<[imageArray count];i++)
{
UIImageView *imageView=[[UIImageView alloc]initWithImage:[imageArray objectAtIndex:i]];
imageView.frame=CGRectMake((i*320)+(i*20), 0, 320, 480);
[imageView_ setTag:i];
[scrollView_ addSubview:imageView];
[imageView release];
}
[self.view addSubview:scrollView_];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [scrollView_ viewWithTag:page_];
}
- (void)scrollViewDidScroll:(UIScrollView *)_scrollView
{
CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.page_=page;
}
提前致谢..
答案 0 :(得分:0)
你在哪里设置 -
[self.mainScroll setZoomScale:(float)];
我猜默认情况下这是1.所以没有缩放发生...
答案 1 :(得分:0)
创建容器视图,并将imageViews添加到容器视图中, 然后使用容器视图作为缩放视图。
- viewDidLoad {
// ---
self.containerView =[[[UIView alloc] init] autorelease];
self.containerView.frame = CGRectMake(0, 0, [imageArray count]*self.scrollView_.frame.size.width, self.scrollView_.frame.size.height);
[scrollView_ addSubView:self.containerView];
for(int i=0;i<[imageArray count];i++)
{
UIImageView *imageView=[[UIImageView alloc]initWithImage:[imageArray objectAtIndex:i]];
imageView.frame=CGRectMake((i*320)+(i*20), 0, 320, 480);
[imageView_ setTag:i];
[self.containerView addSubview:imageView];
[imageView release];
}
// --
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.containerView;
}