I have two scrollviews placed side by side and they can be zoomed individually. So far, it works fine. Now, there's a requirement to zoom the two images together. I was given the roambi app as reference in which two scrollviews can be scrolled together by scrolling either one of them for convenience during comparison. I've gone through scrollview delegate methods but was unable to achieve the required results. How do I do this?
Answer:
Answer:
I had implemented something similar a while ago (I did it for buttons). This is how I did it:
Take two
Take two
Take two
UIScrollView
s and reference them (I've used firstScrollView
and secondScrollView
)Take two
UIButton
s and reference them (I've used firstImgBtn
and secondImgBtn
). Set the delegates to both the scrollviews and use the following delegate methods:- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
//return the respective button in the scrollview to be zoomed
if(scrollView==firstScrollView){
return firstImgBtn;
}
else{
return secondImgBtn;
}
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
// zoom in the other scrollview when one has zoomed
if(zoomTogether){//a bool to decide whether to zoom the two together or not
if(scrollView==firstScrollView){
secondScrollView.zoomScale = firstScrollView.zoomScale;
}
else{
firstScrollView.zoomScale = secondScrollView.zoomScale;
}
}
}
This can be applied to any subclass of UIView
-in your case it will be UIImageView
s
No comments:
Post a Comment