我創建了一個cust UIView類,以便我可以顯示Map對象的內容。經過大量的研究,我仍然無法確定爲什麼下面的方法不畫任何東西:UIImage drawinrect方法不繪製圖像
- (void)drawRect:(CGRect)rect
{
if(_map!=nil){
UIGraphicsBeginImageContext(rect.size);
UIImage *img = [UIImage imageNamed:@"grass"];
float w = rect.size.width/_map.width;
float h = rect.size.height/_map.height;
for(int x=0; x<_map.width; x++){
for(int y=0; y<_map.height; y++){
Tile *tile = [_map getTileAtX:x Y:y];
UIImage *img = [UIImage imageNamed:NSStringFromTileType(tile.type)];
[img drawInRect:CGRectMake(x*w, y*h, w, h)];
}
}
UIGraphicsEndImageContext();
}
}
我打電話[mapView setNeedsDisplay]
刷新UIView的。
任何幫助將不勝感激。謝謝!
如果您在該「」UIGraphicsBeginImageContext「」行上設置斷點,Xcode是否會停在那裏? –