所以我使用CATiled圖層來創建我自己的平面圖。我的平面圖在4,4,5,5和6等較舊的設備上工作得很好。但是,當我在6 plus上運行我的程序時,我的縮放級別算法已關閉。 原因如下:當我打電話給我的繪製矩形方法時,我根據設備得到不同的瓷磚寬度。當我打電話給我的照片時,我會按照ZoomLevel_COL_ROW.image的順序打電話給他們。我的縮放級別是2的倍數。所以每次捏縮放時,我的縮放級別按順序調用:2,4,8,16和32.我遇到的問題是我無法弄清楚如何劃分瓦片寬度減512,以獲得適當的縮放級別。所以在6plus上,當視圖加載時,我的初始圖塊寬度爲85.53。所以512/85.3讓我6 - 這不是我的序列的一部分。 但是,在5s我得到了一個128的瓷磚寬度。所以512/128讓我4 - 這是我的序列的一部分,但跳過級別2.所以我有一個艱難的時間確定什麼是一致的算術每次捏縮放時都可以獲取所有縮放級別序列。回想一下,我的順序是2,4,8,16,32。希望我清楚,每個人都明白。謝謝!CA平鋪圖層類的「縮放級別」不一致
- (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];
}
}
}