2013-02-26 108 views
2

我已經編程創建了15個左右的UIImageViews並給了它們標籤。如何以編程方式使用'animationImages'方法創建UIImageViews

我已經使用[UIView anim ......方法來移動它們,使用[self.view viewWithTag:tag]來引用它們。

但是,[self.view viewWithTag:tag]似乎不適用於animationImages。 Xcode狀態屬性animationImages未在'UIView'類型的對象上找到。

我正試圖移動它們並同時爲它們設置動畫。我花了整整一天在網上搜尋答案,但無濟於事。

任何人都可以請幫忙嗎?

回答

3

您需要檢查[self.view viewWithTag:tag]是否屬於UIImageView類型,然後調用animationImages方法。警告指出UIView不支持animationImages,因爲返回類型爲viewWithTag:is a UIView and not UIImageView

您可以嘗試類似的措施:

UIView *aView = [self.view viewWithTag:tag]; 

if ([aView isKindOfClass:[UIImageView class]]) { 
    UIImageView *imageView = (UIImageView *)aView; 
    imageView.animationImages = [NSArray arrayWith....];//some images  
} 
+0

偉大的作品!謝謝你的幫助。只是讓我理解代碼,而不僅僅是剪切和粘貼。當我們說'UIView * aView = [self.view viewWithTag:tag];'我們沒有製作'viewWithTag'的副本,但* aView只是指向['viewWithTag'指向的同一個對象的指針。因此,當我們將更改應用於視圖時,它實際上更新'viewWithTag',因爲它們指向相同的東西? – 2013-02-27 08:57:22

+0

@PaulAndrewHerbert,是的,你是對的。 – iDev 2013-02-27 16:23:15

相關問題