importUIKit
classViewController:UIViewController{
// iOS显示图片基本都采用UIImageView,相当于生活中的相框
overridefuncviewDidLoad() {
super.viewDidLoad()
//屏幕尺寸:IScreen.mainScreen().bounds
letimageView =UIImageView(frame:UIScreen.mainScreen().bounds)
letbackgroundImage =UIImage(named:"BackGround.png")
//设置imageView显示的图片
imageView.image= backgroundImage
view.addSubview(imageView)
/*
let flower = UIImageView(frame: CGRectMake(60, 90, 80, 80))
let flowerImage = UIImage(named:"flower1.tiff")
flower.image = flowerImage
view.addSubview(flower)
//序列帧动画:要播放的图片(animationImages:[UIImage]),播放时间(animationDuration:Double),播放次数(animationRepeatCount)
var flowerImages = [UIImage]()
for i in 1..<19{
//根据i构建图片名字
let imageName = "flower\(i).tiff"
let image = UIImage(named: imageName)
flowerImages.append(image!)
}
flower.animationImages = flowerImages
flower.animationDuration = 19*0.08
// flower.animationRepeatCount = 1
//开始动画
flower.startAnimating()
*/
letflowerFrame =CGRectMake(60,90,80,80)
addImageView(flowerFrame, imageName:"flower", count: (1,19))
letguaFrame =CGRectMake(60,230,80,80)
addImageView(guaFrame, imageName:"gua", count: (1,17))
letplantFrame =CGRectMake(60,370,80,80)
addImageView(plantFrame, imageName:"plants", count: (1,10))
letzombieFrame =CGRectMake(200,370,80,80)
addImageView(zombieFrame, imageName:"zombie", count: (0,22))
}
funcaddImageView(frame:CGRect,imageName:String,count:(Int,Int)){
letimageView =UIImageView(frame: frame)
letimage =UIImage(named:"\(imageName)1.tiff")
imageView.image= image
view.addSubview(imageView)
varimages = [UIImage]()
foriincount.0..1{
//根据i构建图片名字
letimageName ="\(imageName)\(i).tiff"
letimage =UIImage(named: imageName)
images.append(image!)
}
imageView.animationImages= images
imageView.animationDuration=Double(count.1)*0.08
imageView.startAnimating()
}
overridefuncdidReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
网友评论