2012-05-15 33 views
0

我有幾個我想要動態管理的UIImageView實例。我想加載每個可變數組,然後設置每個實例的animationImages屬性。 我的問題:如何將UIImageViews加載到可變數組中,然後如何動態設置屬性? 下面是如何創建動畫對象:如何加載對象並動態設置屬性?

for (int i = 1; i <= 20; i++) {[myAnimation addObject:[UIImage imageNamed: [NSString stringWithFormat:@"frame-%i.png", i]]]; }

以下是我加的對象(非動態):

NSMutableArray *collection = [[NSMutableArray alloc]initWithObjects:imageView1,imageView2,...nil]; 

我不知道如何設置的屬性。我想應該是類似如下:

for (id xxx in collection) { 
    xxx.animationImages=someAnimation;  
} 
+0

你嘗試了for循環?這就是你如何做到的。 –

+0

你有什麼嘗試?是的,它應該看起來類似於你最終的結果,但你實際上試過了什麼? – borrrden

+0

以下是我的: NSMutableArray * collection = [[NSMutableArray alloc] initWithObjects:imageView1,imageView2,imageView3,imageView4,imageView5,imageView6,imageView7,nil]; \t for(id xxx in collection){ \t \t xxx.animationImages = hopAnimation; \t} 錯誤消息:語義問題:在'const __strong id'對象上未找到屬性'animationImages' 另外,我仍然不知道如何動態地將圖像加載到MutableArray中。 – SimonRH

回答

1

只是行前加UIImageView *imageView = (UIImageView *) xxx;在你像這樣使用

for (id xxx in collection) { 
// Here add the line  
xxx.animationImages=someAnimation;  
} 
+0

我試過了,但收到了一條錯誤消息:語義問題:在類型爲'const __strong id'的對象上未找到屬性'animationImages' – SimonRH

+0

好的,我會在我的項目 –

+0

之一檢查它應該是: for(UIImageView * xxx in collection){ xxx.animationImages = someAnimation; } – SimonRH

0

如果您想使用快速枚舉for循環的風格,你需要使用:根據儘管你做什麼

for (UIImageView * xxx in collection) { 
    xxx.animationImages=someAnimation;  
} 

,它看起來應該考慮將這些添加到某些包含視圖中,並將其從管理視圖中的相應layoutSubviews:調用中展開。在那裏你會做這樣的事情(從視圖中包含您的圖像視圖):

for (UIImageView * view in [self subviews]) { 
    // move the image view around as needed. 
} 

將提供更多的細節,如果這是在線與您正試圖完成的任務,但目前還不清楚,什麼你正在嘗試以此代碼「管理」。