抱歉这个简单的问题,但是如何让CAlayers使用for循环呢? 我现在有这个,但这样做的正确方法是什么?
for (int n = 1; n <= 6; n++) {
NSString *theCloud = [NSString stringWithFormat:@"cloudImage%d",n];
NSString *theCloudLayer = [NSString stringWithFormat:@"cloudLayer%d",n];
CALayer *theCloudLayer = theCloud.layer;
}
感谢任何帮助。
答案 0 :(得分:2)
使用NSArray或NSMutableArray,而不是在名称末尾带有数字的一堆变量(也称为穷人阵列)。
这就像是:
NSArray *cloudImages; // Use this to store your objects currently in the cloudLayerN variables
NSMutableArray *cloudLayers = [NSMutableArray array];
for (id cloud in cloudImages) {
[cloudLayers addObject:[cloud layer]];
}