缩放uiscrollview也可以缩放其中一个

时间:2012-03-22 09:24:12

标签: iphone uiscrollview subview zooming uiscrollviewdelegate

我的项目中有一个包含3 UIScrollView的屏幕。 当我尝试缩放其中一个scrollview时,这些滚动视图包含一个图像 我不知道怎么样但是所有人都在一起放大。

这是我的代码:

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

1 个答案:

答案 0 :(得分:1)

缩放时,它为两个scrollViews调用相同的委托。因此,无论哪个scrollView进行缩放,委托方法中的所有内容都会实现。

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

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

检查scrollView委托方法中的标记

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

例如: -

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

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

    }
   return view;
}

希望这有帮助。