【问题标题】:Inconsistent "Zoom level" for CA-tiled layer classCA 平铺图层类的“缩放级别”不一致
【发布时间】:2015-02-23 17:30:41
【问题描述】:

所以我使用 CATiled 图层来创建我自己的平面图。我的平面图在 4、4s、5、5s 和 6 等旧设备上运行良好。但是,当我在 6 plus 上运行我的程序时,我的缩放级别算法是关闭的。 原因如下:当我调用 draw rect 方法时,我会根据设备获得不同的平铺宽度。当我调用我的图像时,我按 ZoomLevel_COL_ROW.image 的顺序调用它们。我的缩放级别是 2 的倍数。所以每次你捏缩放时,我的 ZoomLevel 都会按顺序调用:2、4、8、16 和 32。我遇到的问题是我不知道如何划分图块宽度为 512 以获得适当的缩放级别。所以在 6plus 上,我在视图加载时的初始平铺宽度是 85.53。所以 512/85.3 给我 6 - 这不是我的序列的一部分。 但是,在 5s 上,我得到 128 的平铺宽度。所以 512/128 让我得到 4 - 这是我的序列的一部分,但是跳过了 2 级。所以我很难确定什么会每次捏合缩放时都要采用一致的算法来获取所有缩放级别序列。回想一下,我的序列是 2、4、8、16、32。希望我说清楚了,每个人都明白。谢谢!

- (void)drawRect:(CGRect)rect
{



//    NSLog(@"drawrect %@", NSStringFromCGRect(rect));
    zoomLevel = (512 / (CGRectGetWidth(rect)));

    int size = 512;
    int zoom = 1;

    while (size > 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 <= lastRow; row++) {
        for (int col = firstCol; col <= 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];


        }
    }
}

【问题讨论】:

    标签: ios objective-c catiledlayer


    【解决方案1】:

    找出原因。它与比例因子有关!因为 iPhone 6 plus 的分辨率不同。看看下面的代码:

    scaleFactor = [UIScreen mainScreen].scale;
    
    
    float width = rect.size.width;
    
    
    
    width *= scaleFactor;
    zoomLevel = (512/ width);
    

    【讨论】:

      猜你喜欢
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 2013-02-07
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      相关资源
      最近更新 更多