1

我的项目中有一个屏幕,其中包含 3 UIScrollView。这些滚动视图包含一个图像,当我尝试缩放其中一个滚动视图时,我不知道如何缩放,但它们都一起缩放。

这是我的代码:

if ([FrameString isEqualToString:@"LB"]) {
    leftButton.hidden = YES;

    if (imageLeft == nil) {
        imageLeft = [[UIImageView alloc]initWithImage:pickedImage];
    }

    imageLeft.frame = CGRectMake(0 , 0, imageLeft.frame.size.width/4, imageLeft.frame.size.height/4);
    self.Scrollview.maximumZoomScale = 0.9;
    self.Scrollview.minimumZoomScale = 0.6;
    self.Scrollview.frame = CGRectMake(self.Scrollview.frame.origin.x, self.Scrollview.frame.origin.y, self.Scrollview.frame.size.width, self.Scrollview.frame.size.height);
    [self.Scrollview setContentSize:CGSizeMake(imageLeft.frame.size.width, imageLeft.frame.size.height)];
    self.Scrollview.clipsToBounds = YES;
    self.Scrollview.delegate = self;
    [self.Scrollview setScrollEnabled:YES];
    [self.Scrollview addSubview:imageLeft];
}

if ([FrameString isEqualToString:@"RDB"]) {
    RightDownButton.hidden = YES;
    if (RightDown == nil) {
        RightDown = [[UIImageView alloc]initWithImage:pickedImage];
    }

    RightDown.frame = CGRectMake(0 , 0, RightDown.frame.size.width/3, RightDown.frame.size.height/3);
    self.scrollview1.maximumZoomScale = 0.9;
    self.scrollview1.minimumZoomScale = 0.6;
    self.scrollview1.frame = CGRectMake(self.scrollview1.frame.origin.x, self.scrollview1.frame.origin.y, self.scrollview1.frame.size.width, self.scrollview1.frame.size.height);
    [self.scrollview1 setContentSize:CGSizeMake(RightDown.frame.size.width, RightDown.frame.size.height)];
    self.scrollview1.clipsToBounds = YES;
    self.scrollview1.delegate = self;
    [self.scrollview1 setScrollEnabled:YES];
    [self.scrollview1 addSubview:RightDown];

}
if ([FrameString isEqualToString:@"RUB"]) {
    rightUpButton.hidden = YES;
    if (RightUp == nil) {
        RightUp = [[UIImageView alloc]initWithImage:pickedImage];
    }

    RightUp.frame = CGRectMake(0 , 0, RightUp.frame.size.width/3, RightUp.frame.size.height/3);
    self.scrollview2.maximumZoomScale = 0.9;
    self.scrollview2.minimumZoomScale = 0.6;
    self.scrollview2.frame = CGRectMake(self.scrollview2.frame.origin.x, self.scrollview2.frame.origin.y, self.scrollview2.frame.size.width, self.scrollview2.frame.size.height);
    [self.scrollview2 setContentSize:CGSizeMake(RightUp.frame.size.width, RightUp.frame.size.height)];
    self.scrollview2.clipsToBounds = YES;
    self.scrollview2.delegate = self;
    [self.scrollview2 setScrollEnabled:YES];
    [self.scrollview2 addSubview:RightUp];
}
4

1 回答 1

1

缩放时,它为两个滚动视图调用相同的委托。因此,无论哪个 scrollView 正在缩放,委托方法中的所有内容都会被实现。

解决此问题的一种简单方法是为两个滚动视图设置标签

self.Scrollview.tag = 1adn self.scrollview1.tag = 2

检查 scrollView 委托方法中的标记

并仅在标签与您感兴趣的标签匹配时运行它。

例如:-

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

if (scrollView.tag == TagYouAreInterestedIn){
    //do stuff

    }
   return view;
}

希望这可以帮助。

于 2012-03-22T14:24:04.697 回答