【问题标题】:view images from array's index从数组的索引查看图像
【发布时间】:2012-06-28 18:43:10
【问题描述】:

我创建了一个包含图像的数组,我通过 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];

谢谢!

【问题讨论】:

  • 您想要这些图片有多重要?如果您能找到看起来相似的字体,那么您可以使用常规标签并更新文本。
  • 我知道,但我想为标签的文本创建一个双边框,如果可能的话,它会避免我做很多工作......有可能吗??
  • 我不是很熟悉,但是有一个名为 Core Text 的框架,你可以在这里查看:developer.apple.com/library/mac/#documentation/StringsTextFonts/…>。 Core Text 是一种用于布局文本和处理字体的高级、低级技术。也许你可以用它来做双边框

标签: objective-c xcode animation uiimageview nsarray


【解决方案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

【讨论】:

    【解决方案2】:

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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 2016-01-07
      • 2017-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多