0

我创建了一个包含图像的数组,我通过animationImages 为它们设置动画。但是现在我想从数组索引中查看图像(我想创建一个带有计数的 for 循环,如果我的计数等于 1,那么它将查看数组中索引 1 处的图像)并对它们进行动画处理。我需要它,因为我想查看从 1 到 100 的数字,如果我的数字等于 11,那么我将显示数字 1 twich(以避免创建 100 个数字图像)。我该怎么做?这是我的正确代码:

//Numbers images
UIImage *numberZero = [UIImage imageNamed:@"numberZero.png"];
UIImage *numberOne = [UIImage imageNamed:@"numberOne.png"];
UIImage *numberTwo = [UIImage imageNamed:@"numberTwo.png"];
UIImage *numberThree = [UIImage imageNamed:@"numberThree.png"];
UIImage *numberFour = [UIImage imageNamed:@"numberFour.png"];
UIImage *numberFive = [UIImage imageNamed:@"numberFive.png"];
UIImage *numberSix = [UIImage imageNamed:@"numberSix.png"];
UIImage *numberSeven = [UIImage imageNamed:@"numberSeven.png"];
UIImage *numberEight = [UIImage imageNamed:@"numberEight.png"];
UIImage *numberNine = [UIImage imageNamed:@"numberNine.png"];


//add numbers uiimage to numbersArray
numbersArray = [NSArray arrayWithObjects:numberZero, numberOne, numberTwo, numberThree, numberFour, numberFive, numberSix, numberSeven, numberEight, numberNine, nil];


UIImageView *imgview1 = [[UIImageView alloc] initWithFrame:CGRectMake(40, 90, 240, 240)];
imgview1.animationImages = numbersArray;
imgview1.animationDuration = 2;
imgview1.animationRepeatCount=1;
[imgview1 startAnimating];
[self.view addSubview:imgview1];

谢谢!

4

2 回答 2

1

我有点不确定你的问题,但我猜你正在尝试使用你的图像作为数字来动画计数到 100(?)。因此,UIImageView为每个数字使用一个,都具有相同的动画图像,并以相对的持续时间为不同的位置设置动画:

float onesDurations = 2;
UIImageView *onesPlace = [[UIImageView alloc] init...]; 
onesPlace.animationImages = numbersArray;
onesPlace.animationDuration = onesDurations;

UIImageView *tensPlace = [[UIImageView alloc] init...]; 
tensPlace.animationImages = numbersArray;
tensPlace.animationDuration = 10*onesDurations; // ten times as slow as ones animation

UIImageView *hundredsPlace = [[UIImageView alloc] init...]; 
hundredsPlace.animationImages = numbersArray;
hundredsPlace.animationDuration = 100*onesDurations; // 100 times as slow animation

// add them all to the view
// start their animations
于 2012-06-28T19:02:38.037 回答
0

您可以使用自定义字体显示文本而不是图像。如果要添加边框或轮廓,则需要做更多的工作。这个问题解释了如何在文本中添加大纲。

希望这可以帮助

于 2012-06-28T18:58:46.480 回答