在描述我的问题一个非常基本的问题之前,有没有办法可以UIScrollView
从这个方法返回对象
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
现在我的问题是,我有一个父母,里面scrollview
有多个孩子(所有水平和分页都启用)。scrollview
每个孩子scrollview
都有一个ImageView
。我zoomScale
从服务器获取因素,基于image
,我必须缩放它,问题是当我尝试缩放里面scrollView
有一个孩子image
时,它只缩放最后一个孩子scrollview
。
所以我认为,我需要找到一种方法,我们可以scrollview
将上述书面委托的形式返回给我们。
有人知道如何解决这个问题吗?
这是 UIView 类,我在此添加了滚动视图和图像,并返回了滚动视图代表的图像视图
示例代码:
- (id)initWithFrame:(CGRect)frame image:(UIImage *)image
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor=[UIColor yellowColor];
self.imageView = [[UIImageView alloc] initWithImage:image];
self.imageView.tag = VIEW_FOR_ZOOM_TAG;
self.imageView.frame=frame;//CGRectMake(8,8 ,305, 400);
[self.imageView setContentMode:UIViewContentModeScaleAspectFit];
self.scrollView = [[UIScrollView alloc] initWithFrame:frame];
self.scrollView.minimumZoomScale = 0.4f;
self.scrollView.maximumZoomScale = 2.0f;
self.scrollView.backgroundColor=[UIColor redColor];
self.scrollView.zoomScale = 1.0f;
self.scrollView.contentSize = self.imageView.bounds.size;
self.scrollView.delegate = self;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
[self.scrollView setCanCancelContentTouches:NO];
[self.scrollView addSubview:self.imageView];
[self addSubview:self.scrollView];
NSLog(@"ScrollViewPostion %f",self.scrollView.frame.origin.x);
}
return self;
}
#pragma -mark
#pragma -mark ScrollViewDelegates
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [scrollView viewWithTag:VIEW_FOR_ZOOM_TAG];
}
在我的主 viewController 类中,我正在这样做,但它没有在滚动视图中正确添加所有图像
NSLog(@"Inner scrollFrame and content size %f %f",innerScrollFrame.origin.x,mainScrollView.contentSize.width);
JoinSeeSubView *subView=[[JoinSeeSubView alloc] initWithFrame:innerScrollFrame image:img];
[self.mainScrollView addSubview:subView];
if (i < [self.allUrlArray count]-1) {
innerScrollFrame.origin.x += innerScrollFrame.size.width;
}
i++;
mainScrollView.contentSize = CGSizeMake(innerScrollFrame.origin.x + innerScrollFrame.size.width, mainScrollView.bounds.size.height);