Rajan Kambaliya
Rajan Kambaliya

Reputation: 157

Zoom two UIScrollViews synchronously.

I have two UIScrollViews. Both the scroll views contain an image. Now, I want to zoom second scroll view programmatically if I zoom in the first scroll view manually. I am using -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView method to manually zoom the first scroll view. The second scroll view should be zoomed to the same point and scale. How can I achieve this?

Upvotes: 0

Views: 559

Answers (3)

David Williames
David Williames

Reputation: 1109

Try something like this in the UIScrollViewDelegate method:

override func scrollViewDidScroll(scrollView: UIScrollView){
    otherScrollView.contentOffset = scrollView.contentOffset
    otherScrollView.zoomScale = scrollView.zoomScale
}

Upvotes: -1

kulgal007
kulgal007

Reputation: 1

How about something like this:

CGRect zoomRect;
zoomRect.size.height = manualScrollView.frame.size.height / manualScrollView.zoomScale;
zoomRect.size.width  = manualScrollView.frame.size.width  / manualScrollView.zoomScale;
zoomRect.origin.x = manualScrollView.center.x - (zoomRect.size.width  / 2.0);
zoomRect.origin.y = manualScrollView.center.y - (zoomRect.size.height / 2.0);

[autoScrollView zoomToRect:zoomRect animated:YES];
[autoScrollView setZoomScale:manualScrollView.zoomScale animated:YES];

Upvotes: 0

Pramod
Pramod

Reputation: 1

By using the tag or object of those two scrollviews you can identify the which scroll view you need zoom in viewForZoomingInScrollView method.

e.g

//need to set the tag for scrollviews
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
if(scrollView.tag == 1) 
{
  return firstImageView;
}
 return secondImageView;

}

OR

//need to create the object of used scrollviews
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
if(scrollView == objScrollViewFirst) 

{
  return firstImageView;
}
 return secondImageView;

}

Upvotes: 0

Related Questions