查看数组索引中的图像

时间:2012-06-28 18:43:10

标签: objective-c xcode animation uiimageview nsarray

我创建了一个包含图像的数组,我通过animationImages制作动画。但现在我想从数组索引中查看图像(我想创建一个带有count的for循环,如果我的count等于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];

谢谢!

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

您可以使用自定义字体显示文本而不是图像。如果你想添加边框或轮廓,那么你将不得不做更多的工作。 this question说明了如何为文字添加大纲。

希望这会有所帮助

相关问题