最初は、私が持っていた 1 つの UIImageView をアニメーション化していたときに、このコードが機能していました。しかし、動的に作成されたいくつかのUIImageViewをアニメーション化するように変更しましたが、forループ内で動的に作成されるため、最初のようにアニメーション化するのが難しいと感じています.
override func viewDidLoad() {
super.viewDidLoad()
var sprite: UIImage = UIImage(named: "sprites/areaLocatorSprite.png")!
var locations:NSArray = animal[eventData]["locations"] as NSArray
for var i = 0; i < locations.count; i++ {
println(locations[i]["locationx"])
var locationx = locations[i]["locationx"] as String
var locationy = locations[i]["locationy"] as String
let x = NSNumberFormatter().numberFromString(locationx)
let y = NSNumberFormatter().numberFromString(locationy)
let cgfloatx = CGFloat(x!)
let cgfloaty = CGFloat(y!)
var mapSprite: UIImageView
mapSprite = UIImageView(image: sprite)
mapSprite.frame = CGRectMake(cgfloatx,cgfloaty,10,10)
townMap.addSubview(mapSprite)
timer = NSTimer.scheduledTimerWithTimeInterval(0.35, target: self, selector: Selector("flash"), userInfo: nil, repeats: true)
}
}
func flash() {
var mapSprite:UIImageView?
if mapSprite?.alpha == 1 {
mapSprite?.alpha = 0
} else {
mapSprite?.alpha = 1
}
}
これは、flash 関数内の mapSprite が for ループ内のものと異なるため、機能しません。for ループ内のものを参照してからアニメーション化するにはどうすればよいですか? または、私が現在行っていることのより良い代替手段はありますか?
どうもありがとう!
Xcode 6.2を使用して編集