我想在特定时间段内使图像动画化。在Objective C中它运行良好。然而,在Swift中它没有运作,我的错误在哪里?
Objective-C的代码如下:
-(void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *imgListArray=[NSMutableArray array];
for (int i=0; i<=11; i++)
{
NSString *strImageName=[NSString stringWithFormat:@"c%d.png", i];
NSLog(@"%@",strImageName);
UIImage *image=[UIImage imageNamed:strImageName];
[imgListArray addObject:image];
}
self.imgView.animationImages = imgListArray;
self.imgView.animationDuration =1.0f;
[self.imgView startAnimating];
// Do any additional setup after loading the view, typically from a nib
}
Swift的代码是-
override func viewDidLoad()
{
super.viewDidLoad()
var imgListArray :NSMutableArray = []
for countValue in 1...11
{
var strImageName : String = "c\(countValue).png"
var image = UIImage(named:strImageName) // suggested by Anil
imgListArray.addObject(image)
}
// Swift code HERE for Objective c
}
var image = [UIImage imageNamed(strImageName)]
是什么意思?这是一个数组吗?还是 ObjC 和 Swift 的混合语法? - holex