Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在CATiledLayer顶部添加UIImage_Iphone_Objective C_Uiimage_Catiledlayer_Cgrect - Fatal编程技术网

Iphone 在CATiledLayer顶部添加UIImage

Iphone 在CATiledLayer顶部添加UIImage,iphone,objective-c,uiimage,catiledlayer,cgrect,Iphone,Objective C,Uiimage,Catiledlayer,Cgrect,是否可以在CATiledLayer的顶部绘制UIImage。主要思想是注意视图上的位置。我使用了苹果库中的PhotoScroller示例,并试图在Tiller的顶部添加一个UIImage。任何帮助都将不胜感激 - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); /**** Trying to add UIImage on top of CGRect rect. Bu

是否可以在CATiledLayer的顶部绘制UIImage。主要思想是注意视图上的位置。我使用了苹果库中的PhotoScroller示例,并试图在Tiller的顶部添加一个UIImage。任何帮助都将不胜感激

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

    /**** Trying to add UIImage on top of CGRect rect. But not working.****/
CGRect pointRect = CGRectMake(100,100,32,32);
UIImage *image = [UIImage imageNamed:@"map-pointer32.png"];
[image drawInRect:pointRect];

// get the scale from the context by getting the current transform matrix, then asking for
// its "a" component, which is one of the two scale components. We could also ask for "d".
// This assumes (safely) that the view is being scaled equally in both dimensions.
CGFloat initialScale = CGContextGetCTM(context).a;

NSString *value = [NSString stringWithFormat:@"%.3f", initialScale];
CGFloat scale = [value floatValue];

CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];
CGSize tileSize = tiledLayer.tileSize;

// Even at scales lower than 100%, we are drawing into a rect in the coordinate system of the full
// image. One tile at 50% covers the width (in original image coordinates) of two tiles at 100%. 
// So at 50% we need to stretch our tiles to double the width and height; at 25% we need to stretch 
// them to quadruple the width and height; and so on.
// (Note that this means that we are drawing very blurry images as the scale gets low. At 12.5%, 
// our lowest scale, we are stretching about 6 small tiles to fill the entire original image area. 
// But this is okay, because the big blurry image we're drawing here will be scaled way down before 
// it is displayed.)
tileSize.width /= scale;
tileSize.height /= scale;

// calculate the rows and columns of tiles that intersect the rect we have been asked to draw
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 tileForScale:scale row:row col:col];
        CGRect tileRect = CGRectMake(tileSize.width * col, tileSize.height * row,
                                     tileSize.width, tileSize.height);



        // if the tile would stick outside of our bounds, we need to truncate it so as to avoid
        // stretching out the partial tiles at the right and bottom edges
        tileRect = CGRectIntersection(self.bounds, tileRect);

        [tile drawInRect:tileRect];




        if (self.annotates) {
            // [[UIColor whiteColor] set];
            CGContextSetLineWidth(context, 6.0 / scale);
            CGContextStrokeRect(context, tileRect);
        }
    }
}
}
-(void)drawRect:(CGRect)rect{
CGContextRef context=UIGraphicsGetCurrentContext();
/****正在尝试将UIImage添加到CGRect上,但不起作用****/
CGRect pointRect=CGRectMake(100100,32,32);
UIImage*image=[UIImage ImageName:@“map-pointer32.png”];
[image drawInRect:pointRect];
//通过获取当前变换矩阵,然后询问
//它的“a”分量是两个刻度分量中的一个。我们也可以要求“d”。
//这假定(安全地)视图在两个维度上的比例相等。
CGFloat initialScale=CGContextGetCTM(上下文).a;
NSString*值=[NSString stringWithFormat:@“%.3f”,初始刻度];
CGFloat scale=[value floatValue];
CATiledLayer*平铺层=(CATiledLayer*)[自层];
CGSize tileSize=tiledLayer.tileSize;
//即使在低于100%的比例下,我们也会在完整的坐标系中绘制成一个矩形
//图像。一个50%的瓷砖覆盖了两个100%瓷砖的宽度(在原始图像坐标中)。
//因此,在50%时,我们需要拉伸瓷砖,使宽度和高度加倍;在25%时,我们需要拉伸瓷砖
//使其宽度和高度翻两番;等等。
//(请注意,这意味着随着比例变低,我们绘制的图像非常模糊。比例为12.5%,
//我们的最低比例,我们正在拉伸约6个小瓷砖,以填充整个原始图像区域。
//但这没关系,因为我们在这里画的大模糊图像在之前会缩小
//它将显示。)
tileSize.width/=比例;
tileSize.height/=刻度;
//计算与要求我们绘制的矩形相交的平铺行和列
int firstCol=floorf(CGRectGetMinX(rect)/tileSize.width);
int lastCol=floorf((CGRectGetMaxX(rect)-1)/tileSize.width);
int firstRow=地板(CGRectGetMinY(rect)/tileSize.height);
int lastRow=地板((CGRectGetMaxY(rect)-1)/tileSize.height);

对于(int row=firstRow;row,最好的解决方案可能是在单独的视图中添加图像,而不添加任何CATILDELAYER。 可以添加空视图,并将带有catiledlayer的视图和uiimageview添加到该视图中