title: WKWebView zooming not working properly
body: <p>I am using XWalkView which is a subclass of WKWebView, added as a subview to a container view programmatically. I am trying to zoom the content page of the WKWebView but it does not zoom first time. The WKWebView zooms the content page subsequently, i.e. when I pinch zoom or do double tap zoom it zooms WKWebView itself or container view (my guess) &amp; after that, doing zoom gestures again the content page is zoomed (which is expected behaviour).</p>
  
  <p>The question is that how to make the content page of WKWebView zoom whenever the zoom gesture is performed.</p>
  
  <p>I am conforming to <code>UIScrollViewDelegate</code> protocol in my <code>ViewController.h</code> as below:</p>
  
  <pre><code>@interface ViewController : UIViewController&lt;UIScrollViewDelegate, WKNavigationDelegate, WKUIDelegate&gt;
  </code></pre>
  
  <p>I am setting the delegate to self in <code>viewDidLoad</code> as below:</p>
  
  <pre><code>xWalkView.scrollView.delegate = self;
  </code></pre>
  
  <p>Setting zooming scales in <code>viewDidLoad</code> as below:</p>
  
  <pre><code>xWalkView.scrollView.minimumZoomScale = 1;
  xWalkView.scrollView.maximumZoomScale = 6;
  </code></pre>
  
  <p>&amp; implementing the protocol methods in <code>ViewController.m</code> as below:</p>
  
  <pre><code>-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
      if (shouldPageNotZoom) {
          NSLog(@"viewForZoomingInScrollView YES");
          return nil;
      } else {
          NSLog(@"viewForZoomingInScrollView NO");
          return xWalkView.scrollView.subviews[0];
      }
  }
  
  -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
  
  }
  </code></pre>
  
  <p>I am using a BOOL shouldPageNotZoom &amp; setting it YES or NO based on URL depending on whether zooming is required or not. On pages where zooming is required I can see the log of else block (<code>NSLog(@"viewForZoomingInScrollView NO");</code>) being printed in log area &amp; on pages where zooming is not required I can see the log of if block (<code>NSLog(@"viewForZoomingInScrollView YES");</code>). Which is working. The only problem is content page does not zoom on first zooming gesture instead WKWebView or container view is zoomed (I guess), but zooms on subsequent zoom gestures.</p>
  
  <p><strong>After some observation</strong> I found that subview at index 0 of scrollview is being zoomed the first &amp; subsequent times (but the content page zooms subsequent times not the first time), which is being returned in <code>viewForZoomingInScrollView</code>. Which should be the case, &amp; is. I did this by assigning the tag values to each view &amp; seeing the tag value by logging the tag value in <code>scrollViewDidEndZooming</code> method in log area as below:</p>
  
  <pre><code>-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
      if (shouldPageNotZoom) {
          NSLog(@"viewForZoomingInScrollView YES");
          return nil;
      } else {
          NSLog(@"viewForZoomingInScrollView NO");
          xWalkView.scrollView.tag = 20;
          xWalkView.tag = 15;
          xWalkView.scrollView.subviews[0].tag = 10;
          _containerView.tag = 5;
          return xWalkView.scrollView.subviews[0];
      }
  }
  
  -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
      NSLog(@"tag %li", (long) view.tag);
  }
  </code></pre>
  
  <p>Giving the below log:</p>
  
  <pre><code>2017-11-28 17:21:36.610753+0530 MyApp[4614:241659] tag 10 //Getting this 1st time of zooming
  2017-11-28 17:21:59.369461+0530 MyApp[4614:241659] tag 10 //Getting this at subsequent zooms 
  </code></pre>
  
  <p>I don't know what am I missing.</p>
  
  <p>Please comment if any clarification is needed.</p>