Reputation: 6133
I am trying to scroll on main uiwebview and when it end scrolling, I want to update that scrolling offset to other uiwebview. I can do that successfully by this.
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
//user will drag the file and stop on the spot..no deceleration
if(scrollView == self.showPdfWebview.scrollView && !decelerate)
{
NSLog(@"Offset value in scrollViewDidEndDragging is %@",NSStringFromCGPoint(self.showPdfWebview.scrollView.contentOffset));
[[pdfOn scrollView] setContentOffset:CGPointMake(0, self.showPdfWebview.scrollView.contentOffset.y) animated:YES];
self.testLabel.text= [NSString stringWithFormat:@"Offset value in scrollViewDidEndDragging is %@. Offset value of pdfon is %@. Frame of showpdfwebview is %@. Frame of pdfOn is %@",NSStringFromCGPoint(showPdfWebview.scrollView.contentOffset),NSStringFromCGPoint(pdfOn.scrollView.contentOffset),NSStringFromCGRect(showPdfWebview.frame),NSStringFromCGRect(pdfOn.frame)];
}}
However, there is one problem. My main uiwebview frame and other uiwebview frame size is different. As a result, I think scrolling on my main webview and on other webview is different.If I scroll a lot on my main uiwebview, it scroll only a little on other webview.
I got output like this. So, it is wrong. I would like to know how to solve.
They should be same >> Offset value in scrollViewDidEndDragging is {0,1374}. Offset value of pdfon is (0,565).
Frame of showpdfwebview is {{0,50}, {1024,698}}. Frame of pdfon is {{0,0},{1920,1080}}
Upvotes: 0
Views: 153
Reputation: 119031
scrollViewDidEndDragging:
is just one of the available delegate methods and the scroll view content offset will often continue to change after it has been called (see the decelerate
parameter). So, consider using one of the other methods instead.
Also, if you want a proportional change then you should calculate the percentage offset of the first view and apply that to the second (divide the content offset by the height of v1 and then multiply by the height of v2 to get the v2 content offset).
Upvotes: 1