tags:

views:

44

answers:

0

Hi,

I have two UIView in a UIScrollView with the same size,

UIView *view1;
UIView *view2;

Now my view1 is the content view, so,

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
     return view1;
}

So that it will react in the pinch or expand gestures.

Now I want is if the scale reaches 0.5f the content view will change to view2. So what I did was this,

-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView 
                withView:(UIView *)view atScale:(float)scale
{
    if(scale == 0.5f)
    {
        changeView      = TRUE;
        view1.hidden    = TRUE;
        view2.hidden    = FALSE;
        view2.transform = CGAffineTransformMakeScale(scale,scale);
        view2.frame     = CGRectMake(0,0,
                            view2.size.width,
                            view2.size.height);
    }
}

Then because I want view2 can also handle the pinch/expand gesture I changed the viewForZoomingInScrollView to,

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
     if(changeView)
       return view2;
     else
       return view1;
}

The changing of view from view1 to view2 looks good and same size. But every time I pinch or expand, the view2 change to its original size. Then I use NSLog the current scale and it change to its scale 1.

What do you think is the problem in my code?

Thanks.