Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best solution was proposed by Zsolt in the comments:</p> <blockquote> <p><a href="http://github.com/evgenyneu/ios-imagescroll" rel="noreferrer">http://github.com/evgenyneu/ios-imagescroll</a> check this out. Works perfectly for me.</p> </blockquote> <p>The solution proposed in this repository is to adjust the minimum and current zoom level before displaying the image:</p> <pre><code>@interface MyViewController () &lt;UIScrollViewDelegate&gt; @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end @implementation MyViewController - (void)viewDidLoad { [super viewDidLoad]; self.scrollView.delegate = self; [self initZoom]; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [self initZoom]; } // Zoom to show as much image as possible - (void) initZoom { float minZoom = MIN(self.view.bounds.size.width / self.imageView.image.size.width, self.view.bounds.size.height / self.imageView.image.size.height); if (minZoom &gt; 1) return; self.scrollView.minimumZoomScale = minZoom; self.scrollView.zoomScale = minZoom; } - (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imageView; } </code></pre> <p>However sample conatins issue with zooming out. Image is not getting centered. This can be easily fixed by using the custom scroll view class with the following code in it:</p> <pre><code>@interface MyScrollView : UIScrollView @end @implementation MyScrollView -(void)layoutSubviews { [super layoutSubviews]; UIView* v = [self.delegate viewForZoomingInScrollView:self]; CGFloat svw = self.bounds.size.width; CGFloat svh = self.bounds.size.height; CGFloat vw = v.frame.size.width; CGFloat vh = v.frame.size.height; CGRect f = v.frame; if (vw &lt; svw) f.origin.x = (svw - vw) / 2.0; else f.origin.x = 0; if (vh &lt; svh) f.origin.y = (svh - vh) / 2.0; else f.origin.y = 0; v.frame = f; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload