【问题标题】:How to Zoom a ScrollView Image when Zoom Button Pressed?按下缩放按钮时如何缩放 ScrollView 图像?
【发布时间】:2014-11-12 05:10:13
【问题描述】:

我制作了一个包含 UIScrollview 和 imageview 的应用程序,当我按下缩放按钮时,我的 imageview 包含数组图像,然后我扩展了我的 UiScrollView 大小和我的 Imageview 大小,然后唯一的最后一个数组图像大小被扩展,它与我的第一个图像重叠我想要在按下缩放按钮时制作,然后我的所有图像都被缩放并且彼此不重叠,我为此编写了一个代码,例如

作为初始大小

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);

按下缩放按钮时

-(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。 然后它是仅缩放最后一张图像,它与我的第一张 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];

然后重叠问题得到解决,但我的阵列只有最后一张图像被缩放意味着扩大了它的大小,其他正在重新调整为初始大小,请给我解决方案。

我知道这个问题被问了很多次,但我对此感到困惑,因为没有得到解决方案。

【问题讨论】:

    标签: ios objective-c uiscrollview zooming


    【解决方案1】:

    在这里我得到了我的自我喜欢的答案

    -(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];
    }
    

    【讨论】:

      【解决方案2】:

      您需要使用 UIScrollView 类的“zoomScale”属性......

      https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollview_class/index.html[UIScrollView 类参考]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-01-09
        • 1970-01-01
        • 2015-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-28
        相关资源
        最近更新 更多