title: Inconsistent "Zoom level" for CA-tiled layer class
body: <p>So I am using CATiled layer to create my own floor plan. My floor plan works just fine on older devices like the 4, 4s, 5, 5s and 6. However, when I run my program on the 6 plus, my arithmetic for zoom level is off. <strong>Here's why:</strong> When I call my draw rect method, I get different tile width's based on the device. When I call my images, I call them in the sequence of <strong>ZoomLevel_COL_ROW.image</strong> . My zoom level is multiples of 2. So every time you pinch to zoom, my ZoomLevel is called in order: 2, 4, 8, 16 and 32. My problem I am having is I can't figure out how to divide the tiles width by 512 to get me the appropriate zoom level. So on a 6plus, my initial tile width when the view loads is <strong>85.53</strong>. So 512/85.3 gets me 6 - which is not apart of my sequence. <strong>However</strong>, on a 5s I get a tile width of 128. So 512/128 gets me 4 - which is apart of my sequence, however skips level 2. So I am having a tough time determining what would be a consistent arithmetic to get all zoom level sequences every time you pinch to zoom. Recall that my sequence is 2, 4, 8, 16,32. Hopefully I am clear, and everyone understands. Thanks!</p>
  
  <pre><code>- (void)drawRect:(CGRect)rect
  {
  
  
  
  //    NSLog(@"drawrect %@", NSStringFromCGRect(rect));
      zoomLevel = (512 / (CGRectGetWidth(rect)));
  
      int size = 512;
      int zoom = 1;
  
      while (size &gt; rect.size.width) {
          size /= 2;
          zoom ++;
      }
  
  
  
      NSLog(@"Zoomlevel %d", zoomLevel);
  
      CGSize tileSize = rect.size;
  
      int firstCol = floorf(CGRectGetMinX(rect) / tileSize.width);
      int lastCol = floorf((CGRectGetMaxX(rect)-1) / tileSize.width);
      int firstRow = floorf(CGRectGetMinY(rect) / tileSize.height);
      int lastRow = floorf((CGRectGetMaxY(rect)-1) / tileSize.height);
  
      for (int row = firstRow; row &lt;= lastRow; row++) {
          for (int col = firstCol; col &lt;= lastCol; col++) {
  
              UIImage *tile = [self tileAtCol:col row:row];
  
              float width = tileSize.width;
              float height = tileSize.height;
  
              if (tile.size.width != tile.size.height) {
                  // make sure that smaller tiles aren't stretched
                  float widthRatio = tile.size.width / 512;
                  float heightRatio = tile.size.height / 512;
  
                  width *= widthRatio;
                  height *= heightRatio;
              }
  
              CGRect tileRect = CGRectMake(tileSize.width * col,
                                           tileSize.height * row,
                                           width, height);
  
              tileRect = CGRectIntersection(self.bounds, tileRect);
  
              [tile drawInRect:tileRect];
  
  
          }
      }
  }
  </code></pre>