简体   繁体   中英

content offset changes unexpectedly while zooming programmatically in uiscrollview

I am having 1.0 - 4.0 zoomscale when I zoom after scale 3.7, content offset changes unexpectedly to last visible rect (lower - right).

How to fix this?

Shift your origin of scroll view according to the size of view after zooming.

 - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {

     CGFloat vPadding;
     CGFloat hPadding;
     if ((480-view.frame.size.height)/2 > 0) {
          vPadding=(480-view.frame.size.height)/2;
     }
     else{
          vPadding=0;
     }
     if ((320-view.frame.size.width)/2 > 0) {
          hPadding=(320-view.frame.size.width)/2;
     }
     else{
          hPadding=0;
     }
     yourView.frame = CGRectMake(hPadding, vPadding, view.frame.size.width, view.frame.size.height);

}

OR change scroll view centre accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM