2012-09-14 35 views
0

我有一個像下面定義的路徑一堆:iPhone:存儲圖形路徑作爲恆

_shapeMutablePath = CGPathCreateMutable(); 
CGPathMoveToPoint(_shapeMutablePath, NULL, 95.97,36.29); 
CGPathAddCurveToPoint(_shapeMutablePath, NULL, 96.02,29.11,90.75,23.00,83.54,21.40); 
CGPathAddCurveToPoint(_shapeMutablePath, NULL, 62.64,66.59,64.11,66.96,65.66,67.12); 
CGPathAddCurveToPoint(_shapeMutablePath, NULL, 74.52,68.04,82.49,62.03,83.47,53.69); 
CGPathAddCurveToPoint(_shapeMutablePath, NULL, 83.57,52.83,83.59,51.98,83.54,51.15); 
CGPathAddCurveToPoint(_shapeMutablePath, NULL, 90.74,49.56,96.01,43.45,95.97,36.29); 
CGPathCloseSubpath(_shapeMutablePath); 

他們有的我都相當頻繁重複使用,所以我想知道什麼是存儲的最佳途徑,檢索這些信息?是否有可能把它作爲常量保存在我的常量文件中?

回答

0

的計算時間來創建一個路徑是沒有什麼比時間繪製它在屏幕上,因此它不應該是隨需隨靜態方法或東西創建一個問題

另外,您能有這樣的存儲要在不同的路徑類的靜態再使用

0

你總是可以只延遲加載這樣

添加屬性

@property (nonatomic, assign, readonly) CGMutablePathRef shapeMutablePath; 

然後覆蓋吸氣

- (CGMutablePathRef)shapeMutablePath; 
{ 
    if (!_shapeMutablePath) { 
    _shapeMutablePath = CGPathCreateMutable(); 
    CGPathMoveToPoint(_shapeMutablePath, NULL, 95.97,36.29); 
    CGPathAddCurveToPoint(_shapeMutablePath, NULL, 96.02,29.11,90.75,23.00,83.54,21.40); 
    CGPathAddCurveToPoint(_shapeMutablePath, NULL, 62.64,66.59,64.11,66.96,65.66,67.12); 
    CGPathAddCurveToPoint(_shapeMutablePath, NULL, 74.52,68.04,82.49,62.03,83.47,53.69); 
    CGPathAddCurveToPoint(_shapeMutablePath, NULL, 83.57,52.83,83.59,51.98,83.54,51.15); 
    CGPathAddCurveToPoint(_shapeMutablePath, NULL, 90.74,49.56,96.01,43.45,95.97,36.29); 
    CGPathCloseSubpath(_shapeMutablePath); 
    } 
    return _shapeMutablePath; 
} 

您還需要在dealloc的清理

- (void)dealloc; 
{ 
    CGPathRelease(_shapeMutablePath); 
}