我创建了一个包含UIScrollview with imageview的应用程序我的imageview包含数组图像当我按下Zoom按钮然后我扩展了我的UiScrollView尺寸和我的Imageview尺寸然后唯一的最后一个阵列图像尺寸被扩展并且它在我的第一张图像上重叠我当按下Zoom按钮然后我的所有图像都是Zoomed而不是Overlaped时我想写一个代码就像那样
作为初始尺寸
self.zoomScroll.frame=CGRectMake(10, 45, 300, 270);
bigImage.bounds=CGRectMake(0, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
bigImage.frame=CGRectMake(index * self.zoomScroll.frame.size.width, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
按下ZoomButton时
-(IBAction)zoombuttonpressed:(id)sender
{
self.zoomScroll.frame=CGRectMake(10, 40, 300, 400);
bigImage.frame=CGRectMake(10, 40, 300, 400);
[self.zoomScroll addSubview:bigImage];
}
这里zoomScroll是UIScrollview,bigImage是我的UIImageView。 然后它是Zoom Only Last image,它在我的第一张ImageView图像中重叠,请给我解决方案。
这时我修改了代码如
-(IBAction)zoombuttonpressed:(id)sender
{
self.zoomScroll.frame=CGRectMake(10, 40, 300, 400);
for(int index=0; index < [self.imagesa count]; index++)
{
bigImage.bounds=CGRectMake(0, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
bigImage.frame=CGRectMake(index * self.zoomScroll.frame.size.width, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
}
[self.zoomScroll addSubview:bigImage];
然后重叠的问题得到了解决,但是我的阵列只有最后一张图像是Zoomed意味着扩展它的大小而其他的重新作为初始大小请给我解决方案。
我知道这个问题被问了很多次,但我对此感到困惑,因为没有得到解决方案。
答案 0 :(得分:0)
我在这里得到了一个自我喜欢的答案
-(IBAction)showbuttonpressed:(id)sender
{
self.zoomScroll.frame=CGRectMake(10, 40, 300, 400);
for(int index=0; index < [self.imagesa count]; index++)
{
NSDictionary *dict=[self.imagesa objectAtIndex:index];
NSString *image=[dict valueForKey:@"link"];
bigImage=[[UIImageView alloc]init];
bigImage.userInteractionEnabled=TRUE;
bigImage.bounds=CGRectMake(0, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
bigImage.frame=CGRectMake(index * self.zoomScroll.frame.size.width, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
[bigImage setMultipleTouchEnabled:YES];
[bigImage setTag:1];
[bigImage sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:[UIImage imageNamed:@"1.png"]];
[bigImage setUserInteractionEnabled:TRUE];
[self.objectarray insertObject:bigImage atIndex:index];
[self.zoomScroll addSubview:bigImage];
self.zoomScroll.clipsToBounds=YES;
[self.zoomScroll addSubview:[self.objectarray objectAtIndex:index]];
}
[self.zoomScroll addSubview:bigImage];
}
答案 1 :(得分:0)
您需要使用&#34; zoomScale&#34; UIScrollView Class的属性....
https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollview_class/index.html [UIScrollView类参考]